无法显示隐藏的跨度

时间:2012-08-29 05:11:00

标签: jquery html

我想在点击按钮时显示隐藏的跨度。 我的HTML看起来像:

<ul>
    <li>
         <span  class="sfFormlabel" style="display:none" >show</span>
        <div id="div1">
          <input type="button" value="show" class="show">
        </div>
    </li>
    <li>
         <span  class="sfFormlabel" style="display:none" >show1</span>
        <div id="div2">
          <input type="button" value="show" class="show">
        </div>
    </li>
</ul>

和jquery:

$('.show').live("click", function () {
    alert('test');
$(this).parent('li').children('span').show();
});

但我没有表现出隐藏的跨度 jsfiddle

2 个答案:

答案 0 :(得分:1)

您需要使用.parents.closest代替.parent

$(this).parents('li').children('span').show();

$(this).closest('li').children('span').show();

PS: .live已弃用,请改用.on

答案 1 :(得分:0)

这是一个简单的解决方案:

$(document).ready(function() {
    $("#about").css("background-color","#222222");  

    $('.show').live("click", function () {
    alert('test');
$('.sfFormlabel').show();
});

});
相关问题