标签:move dev htm 按键 else keycode 选中 ons document
document.onkeydown = function (event) {
if (window.event){
console.log("我是IE、或者chrome");
console.log(event.keyCode); /!*IE chrome*!/
}else{
console.log("我是除chrome的W3C");
console.log(event.which); /!*W3C*!/
}
};
document.onkeydown = function (event) {
console.log(event.keyCode);
};
document.onkeypress = function (event) {
console.log(event.keyCode);
};
var btn3 = document.getElementById("btn3");
btn3.onclick = function () {
console.log("Hello");
};
btn3.onclick = function () {
console.log("Hello3")
};
btn3.addEventListener("click",function () {
alert("Hello1");
});
btn3.addEventListener("click",function () {
alert("Hello2");
});
if (btn3.attachEvent){
/*IE低版本*
btn3.attachEvent("onclick",function () {
alert("IE Hello");
});
}else{
/*IE高版本 和W3C浏览器*/
btn3.addEventListener("click",function () {
alert("W3C Hello");
});
}
<script> var div1 = document.getElementById("div1"); div1.addEventListener("click",function (event) { event.stopPropagation(); alert("div1"); },false); var div2 = document.getElementById("div2"); div2.addEventListener("click",function (event) { event.stopPropagation(); alert("div2"); },false); var div3 = document.getElementById("div3"); div3.addEventListener("click",function (event) { event.stopPropagation(); alert("div3"); },false); var div4 = document.getElementById("div4"); div4.addEventListener("click",function (event) { event.stopPropagation(); alert("div4"); },false); </script>
标签:move dev htm 按键 else keycode 选中 ons document
原文地址:http://www.cnblogs.com/ytsbk/p/7375180.html