标签:
阻止默认行为:
1.实例-简易修改右键菜单
<script>
document.oncontextmenu=function (ev)
{
var oEvent=ev||event;
var oUl=document.getElementById(‘ul1‘);
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(‘ul1‘);
oUl.style.display=‘none‘;
};
</script>
2.实例--阻止表单提交
<script>
window.onload=function ()
{
var oForm=document.getElementById(‘form1‘);
oForm.onsubmit=function ()
{
return false;
};
};
</script>
3.实例3--只能输入数字的文本框
<script>
window.onload=function ()
{
var oTxt=document.getElementById(‘txt1‘);
oTxt.onkeydown=function (ev)
{
var oEvent=ev||event;
//alert(oEvent.keyCode);
//0 48
//9 57
//退格 8
if(oEvent.keyCode!=8 && (oEvent.keyCode<48 || oEvent.keyCode>57))
{
return false; //除数字和退格之外的键的默认行为被禁用
}
//return false;
};
};
</script>
----clientWidth
<script>
document.onclick=function ()
{
alert(document.documentElement.clientWidth);
};
</script>
博客:JS中关于clientWidth offsetWidth scrollWidth等的含义--
http://www.cnblogs.com/fullhouse/archive/2012/01/16/2324131.html
标签:
原文地址:http://www.cnblogs.com/lanyueff/p/4607152.html