標籤:on() width get html onclick blog turn 自訂菜單 alert
<!doctype html><html><head><meta charset="utf-8"><title>無標題文檔</title><style>*{margin:0px;padding:0px;}#div1{position:absolute;width:200px;background:#F00;color:#FFF;display:none;}</style><script>
//點擊右鍵出現自訂菜單document.oncontextmenu=function(ev){var oEvent= ev||event;var oUl=document.getElementById("div1");oUl.style.display="block";oUl.style.left=oEvent.clientX+‘px‘;oUl.style.top=oEvent.clientY+‘px‘;return false;}document.onclick=function(){var oUl=document.getElementById("div1");oUl.style.display="none";}</script></head><body><div id="div1"><ul id="ul1"><li>aaa</li><li>bbb</li><li>ccc</li></ul></div></body></html>
普通寫法 return false
輸入框只能輸入數字
<!doctype html><html><head><meta charset="utf-8"><title>無標題文檔</title><script>window.onload=function(){var oTxt=document.getElementById(‘tex1‘);oTxt.onkeydown=function(ev){var oEvent= ev||event;//alert(oEvent.keyCode);if(oEvent.keyCode!=8&&(oEvent.keyCode<49||(57<oEvent.keyCode&&oEvent.keyCode<96)||oEvent.keyCode>105)){return false;};};};</script></head><body><input type="text" id="tex1"></body></html>
js oncontextmenu阻止右鍵預設菜單 預設行為