如果我有这样的输入文本框:
<input type="text" id="searchField" name="searchField" />
如何使用 javascript 或 jQuery 设置文本字段的值?
你会认为这很简单,但我已经尝试了以下方法:
使用默认值
var a = document.getElementById("searchField");
a.value = a.defaultValue;
使用 jQuery
jQuery("#searchField").focus( function()
{
$(this).val("");
} );
使用js
document.getElementById("searchField").value = "";
他们都没有这样做... :/
最佳答案
在 JavaScript 中:
document.getElementById('searchField').value = '';
在 jQuery 中:
$('#searchField').val('');
应该这样
关于javascript - 在javascript中重置文本框值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7174265/