密码验证时我们可能要检测大写锁定是否开启,代码如下
1
2
3
4
5
6
7
8
| function isCapsLockOn(e){
var c = e.keyCode || e.which;
var s = e.shiftKey || (c.keyCode == 16);
if(((c >= 65 && c <= 90) && !s) || ((c >=97 && c <= 122) && s)){
return true;
}
return false;
} |
Copy Code
参数e为event对象
需要注意的是捕捉的事件必须是’onkeypress’
如果当前页面的域是www.xxxx.com,页面中认为设置了
document.domain = “xxxx.com”;
这时在firefox2里面对于ajax请求是没问题的,但是处理返回的xml文档时会报以下错误
Permission denied to call method XMLDocument.getElementsByTagName
会警告你没有权限处理此文档,解决方法如下:
1
2
3
4
5
6
7
8
| //假设r为xmlhttp对象
if(window.ActiveXObject){
r = r.responseXML;
}else if (window.XMLHttpRequest) {
var parser = new DOMParser();
r = parser.parseFromString(r.responseText, "text/xml");
}
return r; |
Copy Code
当你调用一个form的submit()方法却发现出现上述错误提示,肯定是因为form里面有一个id或者name为”submit”的元素,这时xxform.submit是指向此元素的引用,从而无法执行submit()方法
1
2
3
4
5
6
7
8
9
10
11
12
13
| <html>
<body>
<form id="myform" action="xx.html">
<input type="text" name="submit" />
<input type="button" value="click me" onclick="showMessage()" />
</form>
</body>
</html>
<script>
function showMessage(){
alert(document.getElementById('myform').submit.tagName);
}
</script> |
Copy Code |
Run Code