我有一个while语句,它呼应了大约10个不同的故事。每个故事都有一个用户评论。单击按钮编辑时,我希望其中一个功能隐藏用户评论。这是我编写的代码,试图实现它。如果您想到为什么这不起作用,请告诉我。
<script>
$(".edit_<?php echo $story_id ?>").click(function () {
$(".comment_<?php echo $story_id ?>").hide("fast");
});
</script>
<?php
if (!empty($user_comment))
echo "
<p class='user_comment comment_$story_id'><strong>$user_comment</strong> <a class='edit_story_comment edit_$story_id'>Edit</a></p>";
else
echo "<p id='user_comment_$story_id'><span id='edit_no_story_comment'>Edit</span></p>";
?>
所以我要去 ges 它对 ankertag 的 becuse 是在你之后定义的使用 jquery 提升事件
使用 jQuery on Load 事件来解决此问题
$(function() {
$(".edit_<?php echo $story_id ?>").click(function () {
$(".comment_<?php echo $story_id ?>").hide("fast");
});
});
希望这个帮助
(混合PHP HTML和jQuery以及字符串连接是美丽的顺便说一句:D)