使用 jquery 从文本框中清除旧值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22742995/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
clear the old values from textbox using jquery
提问by sandipon
I am looking for a way to clear the old values from text box when I refresh the page using jquery. I tried this code but it didn't work.
当我使用 jquery 刷新页面时,我正在寻找一种方法来清除文本框中的旧值。我试过这段代码,但没有用。
$('#flip_list_search').value = "";
回答by Max Langerak
Try this
尝试这个
$("#flip_list_search").val('');
回答by Tushar Gupta - curioustushar
Use .val()
使用.val()
$('#flip_list_search').val('');
or
或者
$('#flip_list_search')[0].value ='';
.value
works with native DOM Object $('#flip_list_search')
is jQuery Object
.value
适用于本机 DOM 对象$('#flip_list_search')
是 jQuery 对象
$('#flip_list_search')[0]
to get first native DOM Object
$('#flip_list_search')[0]
获取第一个原生 DOM 对象
回答by Arif
$("input#flip_list_search","#Your_form_Id").val('');
You can use this. It will be more help to detect your element. Here #Your_form_Idis the id that contains your text box. jQuery search your text box only the #Your_form_Idportion in lieu of whole DOM.
你可以用这个。检测您的元素会更有帮助。这里#Your_form_Id是包含您的文本框的 ID。jQuery 只搜索你的文本框#Your_form_Id部分而不是整个 DOM。
回答by Ehsan Sajjad
this will work for you:
这对你有用:
$('#flip_list_search').val("");