Twitter bootstrap collapse: change display of toggle button

后端 未结 10 731
有刺的猬
有刺的猬 2020-12-12 23:50

I am using Twitter Bootstrap to create collapsible sections of text. The sections are expanded when a + button is pressed. My html code as follows:

<         


        
10条回答
  •  孤城傲影
    2020-12-13 00:21

    try this. http://jsfiddle.net/fVpkm/

    Html:-

    MyHeading

    Here comes the text...

    JS:-

    $('button').click(function(){ //you can give id or class name here for $('button')
        $(this).text(function(i,old){
            return old=='+' ?  '-' : '+';
        });
    });
    

    Update With pure Css, pseudo elements

    http://jsfiddle.net/r4Bdz/

    Supported Browsers

    button.btn.collapsed:before
    {
        content:'+' ;
        display:block;
        width:15px;
    }
    button.btn:before
    {
        content:'-' ;
        display:block;
        width:15px;
    }
    

    Update 2 With pure Javascript

    http://jsfiddle.net/WteTy/

    function handleClick()
    {
        this.value = (this.value == '+' ? '-' : '+');
    }
    document.getElementById('collapsible').onclick=handleClick;
    

提交回复
热议问题