我有下面的代码应该被点击父当从“显示更多”,以“显示更少”的h2的值更改,然后再回来。jQuery的切换文本只改变一次
的,如果()测试确定,改变了文本显示更少,但它绝不会再次改变它,总是显示警报“显示更多”,所以它只是没有检测到其他()条件。
我已搜查高和低,找出原因,但还没有找到一个解决办法。
我知道这是一个noob问题该这么道歉,但我试图在这里发布之前找到解决方案。
谢谢。
$('#panels > .feature').click(function() {
if($(this).children('h2').val('Show More')) {
$(this).children('h2').text('Show Less');
alert('Show More was found');
}
else {
$(this).children('h2').text('Show More');
alert('Show Less was found');
}
$(this).next(".info_box").animate(
{'height':'toggle'}, 'slow', 'linear'
);
});
的HTML中的问题是:
<div id="panels">
<div id="Email" class="feature">
<h1>LiveContent</h1><h2>Show More</h2>
</div>
<div class="info_box">Information will go in this div which should slide in and out.</div>
<div id="Email" class="feature">
<h1>Publishing Solutions</h1><h2>Show More</h2>
</div>
<div class="info_box">Information will go in this div which should slide in and out.</div>
<div id="Email" class="feature">
<h1>Title 1</h1><h2>Show More</h2>
</div>
<div class="info_box">Information will go in this div which should slide in and out.</div>
</div>
对于格式良好的问题+1。 – Matt 2010-11-29 13:12:30