Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 单击getElementByID(字段)。输入值=x_Javascript_Html_Dom - Fatal编程技术网

Javascript 单击getElementByID(字段)。输入值=x

Javascript 单击getElementByID(字段)。输入值=x,javascript,html,dom,Javascript,Html,Dom,我正试图从窗体中清除一个字段。现在它被重置为默认值,但是我想清除它,这样它就没有值或者有一个空格作为值 PHP正在编写这段代码 <script> function resetInput() { var x=\"\"; document.getElementById(\"playerName\").value=x; } </script> <form name=\"input\" action=\"search.php\" method=\"get\"

我正试图从窗体中清除一个字段。现在它被重置为默认值,但是我想清除它,这样它就没有值或者有一个空格作为值

PHP正在编写这段代码

<script>
function resetInput() 
 {
  var x=\"\";
  document.getElementById(\"playerName\").value=x;
 }
</script>

<form name=\"input\" action=\"search.php\" method=\"get\">
<input id=\"playerName\" class=searchField type=\"text\" name=\"playerName\" value=\"".$_GET['playerName']."\">
<input type=\"submit\" class=searchBut value=\"Search\">
<input onclick=\"resetInput()\" type=\"reset\" class=searchBut value=\"Clear\">

</form>
我删除了此表单中的其他输入,但还有其他输入,我希望重置按钮将所有输入重置为默认值,并清除playerName输入

非常感谢各位。

您的按钮类型是“重置”,其默认操作是将窗体重置为默认值。因此发生了什么-在
onclick中,将
playerName
的值重置为“”,然后默认的“重置”操作将包括
playerName
在内的所有字段重置为默认值

由于您确实希望将其余字段重置为默认值,因此应保留默认的“重置”操作。您只需在默认操作后运行函数
resetInput
。一种方法是在一个小的超时时间:

<input onclick=\"setTimeout(resetInput,10)\" type=\"reset\" class=searchBut value=\"Clear\">


你他妈的为什么要避开引号?为什么要使用
\“
?它是在php中,我刚刚粘贴了将被回响的内容的内部。@Satpal…正如OP所说,php正在编写这段代码。它工作得很好。我曾经尝试过,但使用window.setInterval(resetInput(),500),但没有成功。非常感谢。
<input onclick=\"setTimeout(resetInput,10)\" type=\"reset\" class=searchBut value=\"Clear\">