提交表单后清除 jQuery 中的表单字段



提交评论后,我的评论表单会向上滑动并隐藏。我正在使用以下代码:

$("#pm-post-form").slideUp("normal", function(){
$("#mycommentspan").html(g.html).show();
if (g.preview == true) {
$("#be_the_first").hide();
$("#preview_comment").html(g.preview_html).fadeIn(700)
}
})

但我不想再隐藏它了,所以用户可以放置其他人的评论。

我尝试了这段代码但没有成功:

$("#pm-post-form").val("", function(){
$("#mycommentspan").html(g.html).show();
if (g.preview == true) {
$("#be_the_first").hide();
$("#preview_comment").html(g.preview_html).fadeIn(700)
}
})

我使用val("")在提交评论后清除表单字段内容,但它不起作用。

我尝试了这个有效的解决方案。

$("#mycommentspan").html(g.html).show();
if (g.preview == true) {
$("#be_the_first").hide();
$("#preview_comment").html(g.preview_html).fadeIn(700); // comment placed
$("#c_comment_txt").val("") // textarea where use place comment, that after submission is cleared
}

提交后,用户可以在不刷新页面的情况下放置新评论。

最新更新