简体   繁体   中英

Clear form field in jQuery after form submission

After submission comments, my comment form slides up and hides. I'm using this code, which works:

$("#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)
    }
})

But I don't want hide it anymore, so users can place others comments.

I tried this code without success:

$("#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)
    }
})

I used val("") to clear form field content after comment submission, but it doesn't work.

I tryed this solution that works.

$("#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
 }

After submission, user can place new comment without refresh page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM