黑马程序员技术交流社区
标题:
有一道js题
[打印本页]
作者:
李朋霏
时间:
2012-7-21 12:32
标题:
有一道js题
一个按钮,如果点击左键提示“禁止点击左键”,点击右键则提示“禁止点击右键”,然后提示2分钟后自动关闭页面。
作者:
刘建素
时间:
2012-7-21 13:58
<script type="text/javascript">
function Click() {
GetMouseKey(event.button);
}
function GetMouseKey(button) {
if (button == 1) //event.button==1 鼠标左键
{
alert("单击了左键");
setTimeout(function () {
window.close();
}, 2000); //关闭窗体
}
if (button == 2 || button == 0) // 测试在IE中按右键是2,在Maxthon2.0正式版中是0,IE中默认是0
{
alert("单击了右键");
setTimeout(function () {
window.close();
}, 2000);//关闭窗体
}
}
</script>
//调用时间html
<div style="background-color: Gray;" oncontextmenu="return false" onmousedown="Click()">
测试鼠标点击事件
</div>
作者:
许庭洲
时间:
2012-7-23 16:37
本帖最后由 许庭洲 于 2012-7-23 16:39 编辑
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>用JS实下功能,左键点击页面显示“点击了左键”右键点击显示“现在禁止右键”并在2分钟后自动关闭页面</title>
<form id="form1" runat="server">
<iframe style="display:none" name=if0 ></iframe>
</form>
<script>
function document.oncontextmenu()
{
event.returnValue=false;
}
function click()
{
if(event.button==2)
{
aaa=if0.showModelessDialog("javascript:alert(' 鼠标右键被点击'); window.close();","","status:no;resizable:no;help:no;dialogHeight:30px;dialogWidth:40px;");
setTimeout("if0.location.reload();",2000);
}
if (event.button==1)
{
aaa=if0.showModelessDialog("javascript:alert('鼠标左键被点击'); window.close();","","status:no;resizable:no;help:no;dialogHeight:30px;dialogWidth:40px;");
setTimeout("if0.location.reload();",2000);
}
}
document.onmousedown=click
</script>
</head>
<body>
</body>
</html>
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2