在javascript中重置文本框的值

15 浏览
0 Comments

在javascript中重置文本框的值

如果我有一个像这样的输入文本框:


如何使用javascript或jQuery设置文本框的值?

你可能会认为这很简单,但我已经尝试了以下方法:

使用defaultValue

var a = document.getElementById("searchField");
a.value = a.defaultValue;

使用jQuery

jQuery("#searchField").focus( function()
{ 
  $(this).val(""); 
} );

使用js

document.getElementById("searchField").value = "";

但是,以上方法都无法实现... :/

0