在javascript中重置文本框的值 [英] Reset textbox value in javascript
本文介绍了在javascript中重置文本框的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有这样的输入文本框:
< input type =textid =searchFieldname =searchField/>
如何使用javascript或jQuery设置文本字段的值?
您可能认为这很简单,但我尝试了以下方法:
使用defaultvalue
var a = document.getElementById(searchField);
a.value = a.defaultValue;
使用jQuery
jQuery(#searchField)。focus(function()
{
$(this).val();
} );
使用js
document.getElementById(searchField)。value =;
他们都没有这样做......:/
document.getElementById('searchField')解决方案
.value ='';
在jQuery中:
$( '#searchField')VAL( '');
这应该做到这一点
If I have a input textbox like this:
<input type="text" id="searchField" name="searchField" />
How can I set the value of the textfield using javascript or jQuery?
You would think this was simple but I've tried the following:
Using defaultvalue
var a = document.getElementById("searchField");
a.value = a.defaultValue;
Using jQuery
jQuery("#searchField").focus( function()
{
$(this).val("");
} );
Using js
document.getElementById("searchField").value = "";
None of them are doing it... :/
解决方案
In Javascript :
document.getElementById('searchField').value = '';
In jQuery :
$('#searchField').val('');
That should do it
这篇关于在javascript中重置文本框的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文