Clear text field value in JQuery

前端 未结 15 1407
情书的邮戳
情书的邮戳 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:11

    If you want to have element with visible blank text just do this:

    $('#doc_title').html(' ');
    
    0 讨论(0)
  • 2020-12-05 13:13

    If you want to clear the text field, use:

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

    Use jQuery.prototype.val to get/set field values:

    var value = $('#doc_title').val();    // get value
    $('#doc_title').val('');    // clear value
    
    0 讨论(0)
  • 2020-12-05 13:15
    $('#[element id]').val(null);
    

    or

    $('.[element class]').val(null);
    
    0 讨论(0)
  • 2020-12-05 13:21

    If you are using jQuery, then you can use this:

    // var doc_val_check = $('#doc_title').val(); - No need of this!
    if ($('#doc_title').val().length > 0) {
        $('#doc_title').val("");
    }
    
    0 讨论(0)
  • 2020-12-05 13:22

    What you need is:

    if ($('#doc_title').val()) {
      $('#doc_title').val('');
    }
    
    0 讨论(0)
提交回复
热议问题