Clear text field value in JQuery

2019-01-23 10:38发布

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 is the relevant code that is suppose to grab the current value of the text field, if a value exists, clear it that is contained within the .change function:

var doc_val_check = $('#doc_title').attr("value");
    if (doc_val_check.length > 0) {
        doc_val_check == "";
    }

I feel like I am missing something very simple.

14条回答
太酷不给撩
2楼-- · 2019-01-23 11:02
$('#[element id]').val(null);

or

$('.[element class]').val(null);
查看更多
老娘就宠你
3楼-- · 2019-01-23 11:03

In simple way, you can use the following code to clear all the text field, textarea, dropdown, radio button, checkbox in a form.

function reset(){
    $('input[type=text]').val('');  
    $('#textarea').val(''); 
    $('input[type=select]').val('');
    $('input[type=radio]').val('');
    $('input[type=checkbox]').val('');  
}
查看更多
登录 后发表回答