我有以下的代码,应该可以在父元素被点击时将h2的值从"Show More"更改为"Show Less",然后再次更改回来。
if()测试良好并将文本更改为“显示较少”,但它永远不会再次更改它,并始终显示警告“显示更多”,因此它无法检测else()条件。
我已经费尽了心思去寻找原因,但还没有找到解决办法。
我知道这是新手问题,所以向大家道歉,但我已经在发帖前尽力寻找解决方案了。
谢谢。
if()测试良好并将文本更改为“显示较少”,但它永远不会再次更改它,并始终显示警告“显示更多”,因此它无法检测else()条件。
我已经费尽了心思去寻找原因,但还没有找到解决办法。
我知道这是新手问题,所以向大家道歉,但我已经在发帖前尽力寻找解决方案了。
谢谢。
$('#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'
);
});
The HTML in question is:
<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>