onsubmit="return check();
“时‘;’忘记带导致check函数未执行。
2.当元素是动态生成的时候,要想捕捉其点击事件等事件的时候,要在其一个不是动态生成的元素的层级上对其进行捕捉:
<div class="comment" >
<!--|_________________________________________comment area begin___________________________________________|-->
<foreach name='comments' item='comment' key='k'>
<div class="pinglun">
<div class="tx"><a href="javascript:"><img src="__ROOT__/Home/Tpl/Public/images/tx.jpg" class="img" /></a></div>
<div class="zj">
<{/*user_name and comment from the user*/}>
<span class="wdyhm"><{$comment['user_name']}></span>
<span class="plnr"><{$comment['comment']}></span>
</div>
<div class="yc">
<a href="javascript:" >
<img src="__ROOT__/Home/Tpl/Public/images/zan.png" border="0" id='zan_img'/>
</a>
<{// approving_num to this comment}>
<{// the biggest length of comment:
length of(jack is a good manjack is a good man jack is a good man jack is a good manjack is a good manjack is a good man)}>
<span class="zan" value="<{$comment['id']}>"><{$comment['approving_num']}></span>
</div>
</div>
</foreach>
<script type="text/javascript">
/**
* plus the approving_num
*/
$(".pinglun #zan_img").click(function(){
var approvingNum=$(this).parent().next().text();
approvingNum=parseInt(approvingNum)+1;
$(this).parent().next().text(approvingNum);
});
</script>
</div>
这里的foreach标签中的元素都是动态生成的,如果使用:
*$("#zan_img").click(function(){
var approvingNum=$(this).parent().next().text();
approvingNum=parseInt(approvingNum)+1;
$(this).parent().next().text(approvingNum);
});*
那么只有第一个元素点击的时候管用,其他的则不管用,
当使用:
$(".pinglun #zan_img").click(function(){
时则都管用。
var approvingNum=$(this).parent().next().text();
approvingNum=parseInt(approvingNum)+1;
$(this).parent().next().text(approvingNum);
});