2

I have this code which hides/shows the div on button click. Is there any way I can toggle the button value?

<div>
    <button id="showmenu" type="button">Click Me!</button>
</div>
<div class="menu" style="display: none;">
    Can the button value change to "show" or "hide"
</div>

<script>
    $(document).ready(function() {
        $('#showmenu').click(function() {
            $('.menu').toggle("slide");
        });
    });
</script> 
4

2 回答 2

3

尝试这个:

$(document).ready(function() {
    $('#showmenu').click(function() {
        $(this).text($('.menu').is(':visible') ? 'hide' : 'show');
        $('.menu').toggle("slide");
    });
});
于 2013-08-31T13:41:26.840 回答
0

你可以试试这个

  $(document).ready(function() {
        $('#showmenu').click(function() {
            $('.menu').slideToggle('slow', function() {
                    if($(".menu").is(":visible"))
                    { // Set Show Text
                    }
                    else{ // Set Hide Text
                    }                

            });
        });
    });
于 2013-08-31T13:42:16.890 回答