Clear text field value in JQuery

前端 未结 15 1426
情书的邮戳
情书的邮戳 2020-12-05 12:26

I understand this is an easy question but for some reason this just isn\'t working for me. I have a function that is triggered everytime a drop down menu is changed. Here

相关标签:
15条回答
  • 2020-12-05 13:23

    you can clear it by using this line

    $('#TextBoxID').val("");
    
    0 讨论(0)
  • 2020-12-05 13:23

    We can use this for text clear

    $('input[name="message"]').val("");  

    0 讨论(0)
  • 2020-12-05 13:24
    doc_val_check == "";   // == is equality check operator
    

    should be

    doc_val_check = "";    // = is assign operator. you need to set empty value
    
                           // so you need =
    

    You can write you full code like this:

    var doc_val_check = $.trim( $('#doc_title').val() ); // take value of text 
                                                         // field using .val()
        if (doc_val_check.length) {
            doc_val_check = ""; // this will not update your text field
        }
    

    To update you text field with a "" you need to try

    $('#doc_title').attr('value', doc_val_check); 
    // or 
    $('doc_title').val(doc_val_check);
    

    But I think you don't need above process.


    In short, just one line

    $('#doc_title').val("");
    

    Note

    .val() use to set/ get value in text field. With parameter it acts as setter and without parameter acts as getter.

    Read more about .val()

    0 讨论(0)
提交回复
热议问题