这是我的代码:
$('.reply').click(function() {
$leftwrap = $(this).parent();
$comment = $(leftwrap).parent();
$id = $comment.attr('id');
if($(this).siblings('.reply-form').length == 0) { //check whether or not the form as been initiated yet
$(this).parent().append('<?php $replytimestamp = strtotime("now"); ?>
<form class="reply-form" action="/scripts/reply-process.php" method="post">
<input type="hidden" name="replytimestamp" value="<?php echo $replytimestamp; ?>">
<input type="hidden" name="replyto" value="'+ $id +'">
<label for="name" class="reply-label">Name</label>
<input type="text" name="name" class="reply-input">
<label for="message" class="reply-label">Reply</label>
<textarea name="message"class="reply-ta"></textarea>
<input class="reply-submit" type="submit" name="submit" value="submit" />
</form>');
$(this).siblings('.reply-form').hide();
$(this).siblings('.reply-form').slideDown();
} else $(this).siblings('.reply-form').slideToggle(); //if it is, toggle it
});
当我点击“.reply”时,什么也没有发生,没有幻灯片,什么也没有。我在 Firebug 中找不到任何东西。那么知道怎么回事吗?谢谢!!
最佳答案
我建议始终在 if 语句中使用括号,但无论如何,您的问题就在这里:
$leftwrap = $(this).parent();
$comment = $(leftwrap).parent();
如果您打算这样做,则需要:
$leftwrap = $(this).parent();
$comment = $leftwrap.parent();
$
变量并不神奇,它是变量名称的一部分,因此您必须包含它。
关于javascript - 在 jQuery 中附加表单时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1955952/