【发布时间】:2014-01-03 20:17:34
【问题描述】:
所以我的脚本中有一个表单,所以有很多输入标签。当有人在输入中写东西并意外关闭页面时,应该出现:
alert("You have to fill the whole form.");
这是我现在的代码:
HTML
<input placeholder="name" />
JAVASCRIPT
window.onbeforeunload = function () {
var input = document.getElementByTagName("input");
if (input.value.length > 0){
alert("You have to fill the whole form.");
}
};
我的问题是,我做错了什么?
【问题讨论】:
-
长度长度拼写错误?
-
应该是
input.value.length... 以后也请给出您收到的错误信息。此外,您可能需要检查该值是否不是一堆空格。 -
请使用 getElementById 并检查这篇文章 onbeforeunload 功能,并非每个浏览器都支持window.onbeforeunload and window.onunload is not working in Firefox , Safari , Opera?
标签: javascript jquery html input