Javascript Javascript在按钮单击时清除表单字段
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6750445/
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
Javascript to clear form field on button click
提问by IRHM
I have a field called 'inputaddress' which a user types address details into, so they can perform a google map geocode.
我有一个名为“inputaddress”的字段,用户可以在其中输入地址详细信息,以便他们可以执行谷歌地图地理编码。
What I would like to do is when the user clicks on the 'searchfortheaddress' button, it will perform the geocode but will then clear the 'inputaddress' field.
我想做的是当用户单击“搜索地址”按钮时,它将执行地理编码,但随后会清除“输入地址”字段。
Could someone perhaps tell me please how I can clear the field.
有人可以告诉我如何清除该字段。
回答by Barry Kaye
document.getElementById("inputaddress").value = '';
回答by Eamorr
Would $('#inputaddress').html("");
or document.getElementById('inputaddress').value=""
work?
会$('#inputaddress').html("");
或document.getElementById('inputaddress').value=""
工作?
回答by psynnott
document.getElementById("inputaddress").value = '';
回答by lovesh
i am assuming that u id your input address field addr
just add this code to the onclick
event of your searchforaddress
button
我假设您确定了您的输入地址字段,addr
只需将此代码添加到onclick
您的searchforaddress
按钮事件中
document.getElementById('addr').value="";
like this (i am assuming is of ur searchforaddress
button is searchforaddress
)
像这样(我假设是你的searchforaddress
按钮是searchforaddress
)
document.getElementById('searchforaddress').onclick=function() {
document.getElementById('addr').value="";
};