-1

HTML:

<a href="javascript:void(0);" title="Show and Hide" id="_showhide">
    <span id="textsh">hide</span>
    <div id="contentsShowHide" style="display:none;">
        Contents here
    <div>

JavaScript:

function headerShowHide(){
$(document).ready(function(){
    $('#_showhide').click(function(){
        $('#contentsShowHide').toggle(function(){$("#textsh").text("show")},function(){$("#textsh").text("hide")});
      });
});}

<div id="contentsShowHide">は表示も非表示もされず、 のテキストは変更されません
<span id="textsh">。ここで何が欠けていますか?

4

3 に答える 3

2

使用する

$(document).ready(function(){
    $('#_showhide').click(function(){
        $('#contentsShowHide').toggle(function(){
            $("#textsh").html("show")},function(){
                $("#textsh").html("hide");
            });
        });
    });
});

headerShowHide() を呼び出す必要はありません。

于 2012-10-19T04:40:40.070 に答える
0

このデモを試す

$(document).ready(function(){
$('#_showhide').toggle(function(){
    $("#textsh").text("show");
            $("#contentsShowHide").hide();
}, function(){
                $("#textsh").text("hide"); 
                    $("#contentsShowHide").show();
});
});
于 2012-10-19T04:41:12.257 に答える
0
$('#_showhide').click(function(){   
    if ($('#contentsShowHide').is(":visible"))
    {
      $('#contentsShowHide').hide();
      $("#textsh").text("show");
    }
    else
    {
      $('#contentsShowHide').show();
      $("#textsh").text("hide");
    }
});

ワーキングデモ。シンプルなアプローチ

于 2012-10-19T04:41:47.967 に答える