警报后重置输入值 - Javascript
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10923719/
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
Reset input value after alert - Javascript
提问by Lodder
I have a simple input box where if the number is higher than 2, a popup message will appear.
我有一个简单的输入框,如果数字大于 2,则会出现一个弹出消息。
Here is the code I am using, however I already have an onkeyup
command on the input for something else, so I hope that won't be a problem
这是我正在使用的代码,但是我已经onkeyup
在输入上有了其他命令,所以我希望这不会成为问题
HTML:
HTML:
<input id="jj_input23" type="text" value='' onkeyup='changeTransform()' />
Javascript:
Javascript:
if(jj_input23 > 2) {
alert("Making the scale higher than 2 will make the preview too big");
document.getElementById('jj_input23').value("");
}
After the aler message has been displayed, and the user has clicked "Ok", I want the input text to reset. How can I do this?
显示警报消息并且用户单击“确定”后,我希望重置输入文本。我怎样才能做到这一点?
Thanks in advance
提前致谢
回答by Zoltan Toth
if(jj_input23 > 2) {
alert("Making the scale higher than 2 will make the preview too big");
document.getElementById('jj_input23').value = "";
}
If you're using jQuery then you almost got it:
如果您使用的是 jQuery,那么您几乎就明白了:
$('#jj_input23').val("");
回答by SLaks
.value
is a property, not a function.
.value
是一个属性,而不是一个函数。
You want .value = "";
.
你要 .value = "";
。