大家帮个忙呀,实现一个联系点击几块地方触发一个事件??? 最土的方法,在四个角都放上onclick 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 四个角都放上onclick,那也不对呀!你点一个onclick就触发了,我现在想实现的是“连续点”了这“四个”以后才触发呢。 点一个 onclick 将鼠标移到另外一个角不久行了 你把点击动作都记录在一个全局变量里不就完了?四个链接每次点击后往里面添加 1/2/3/4, 每次点击里都判断如果1234都齐了就触发 xxx 全局数组存event.clientX和event.clientY的坐标,要先判断坐标范围是否是你划定的区域。感觉是在做彩蛋,好玩儿^_^ <table width="100%" height="100%"> <tr> <td><div onclick="t(1)">点击</div></td><td><div onclick="t(2)">点击</div></td> </tr> <tr> <td><div onclick="t(4)">点击</div></td><td><div onclick="t(3)">点击</div></td> </tr></table><script type="text/javascript">var str = ""; // 全局变量function t(num){ str += num; if (str.indexOf("1234") > -1) { // 按顺序点时才执行 alert("OK"); str = ""; }}</script> <html> <head> <style type="text/css"> div { position:absolute; background-color:#efefef; } </style> <script type="text/javascript"> function $(id) { return document.getElementById(id); } function initialize() { $("div1").style.width="100px"; $("div1").style.height="100px"; $("div1").style.left="0"; $("div1").style.top="0"; $("div1").innerHTML="1"; $("div2").style.width="100px"; $("div2").style.height="100px"; $("div2").style.left=document.body.clientWidth-parseInt($("div2").style.width); $("div2").style.top="0"; $("div2").innerHTML="2"; $("div3").style.width="100px"; $("div3").style.height="100px"; $("div3").style.left="0"; $("div3").style.top=document.body.clientHeight-parseInt($("div3").style.height); $("div3").innerHTML="3"; $("div4").style.width="100px"; $("div4").style.height="100px"; $("div4").style.left=document.body.clientWidth-parseInt($("div4").style.width); $("div4").style.top=document.body.clientHeight-parseInt($("div4").style.height); $("div4").innerHTML="4"; } var arr=new Array(); document.onmousedown=function(event){validate(event)}; window.onresize=initialize; function validate(e) { e=e||event; if(e.clientX>parseInt($("div1").style.left) && e.clientX<parseInt($("div1").style.left)+parseInt($("div1").style.width) && e.clientY>parseInt($("div1").style.top) && e.clientY<parseInt($("div1").style.top)+parseInt($("div1").style.height)) { arr.push(1); } else if(e.clientX>parseInt($("div2").style.left) && e.clientX<parseInt($("div2").style.left)+parseInt($("div2").style.width) && e.clientY>parseInt($("div2").style.top) && e.clientY<parseInt($("div2").style.top)+parseInt($("div2").style.height)) { arr.push(2); } else if(e.clientX>parseInt($("div3").style.left) && e.clientX<parseInt($("div3").style.left)+parseInt($("div3").style.width) && e.clientY>parseInt($("div3").style.top) && e.clientY<parseInt($("div3").style.top)+parseInt($("div3").style.height)) { arr.push(3); } else if(e.clientX>parseInt($("div4").style.left) && e.clientX<parseInt($("div4").style.left)+parseInt($("div4").style.width) && e.clientY>parseInt($("div4").style.top) && e.clientY<parseInt($("div4").style.top)+parseInt($("div4").style.height)) { arr.push(4); } else { arr.length=0; } if(arr.length==4 && arr[0]==1 && arr[1]==2 && arr[2]==3 && arr[3]==4) { doSomething(); } }; function doSomething() { alert("Congratulate to next stage!"); }; </script> </head> <body onload="initialize()"> <div id="div1"></div> <div id="div2"></div> <div id="div3"></div> <div id="div4"></div> </body></html>你按1,2,3,4的顺序点就可以看到效果,点错了可以点空白区域重置。 setAttribute设置class属性,只有部分样式有效??? ExtJS的TreePanl加载数据不显示的问题 关于利用正则表达式消除不必要的空格及数字中多余的零的问题!! js更改下拉框选定的默认值 一个简单的innerHTML问题,不知道错哪里了??请指教! 关于javascript和jquery的tree插件 关于表格插入节点的问题 一个很简单的问题 怎么去掉被强制设置的IE启动主页 onunload 事件现在好像很多浏览器都不执行该事件? javascript判断回车就到下一个文本框,当到了提交的超链时就提交。怎么判断啊。 有个功能不知道该如何实现,求助~~~~~~~~
你点一个onclick就触发了,我现在想实现的是“连续点”了这“四个”以后才触发呢。
四个链接每次点击后往里面添加 1/2/3/4, 每次点击里都判断如果1234都齐了就触发 xxx
<tr>
<td><div onclick="t(1)">点击</div></td><td><div onclick="t(2)">点击</div></td>
</tr>
<tr>
<td><div onclick="t(4)">点击</div></td><td><div onclick="t(3)">点击</div></td>
</tr>
</table><script type="text/javascript">var str = ""; // 全局变量
function t(num)
{
str += num;
if (str.indexOf("1234") > -1)
{
// 按顺序点时才执行
alert("OK");
str = "";
}
}</script>
<html>
<head>
<style type="text/css">
div
{
position:absolute;
background-color:#efefef;
}
</style> <script type="text/javascript">
function $(id)
{
return document.getElementById(id);
} function initialize()
{
$("div1").style.width="100px";
$("div1").style.height="100px";
$("div1").style.left="0";
$("div1").style.top="0";
$("div1").innerHTML="1"; $("div2").style.width="100px";
$("div2").style.height="100px";
$("div2").style.left=document.body.clientWidth-parseInt($("div2").style.width);
$("div2").style.top="0";
$("div2").innerHTML="2"; $("div3").style.width="100px";
$("div3").style.height="100px";
$("div3").style.left="0";
$("div3").style.top=document.body.clientHeight-parseInt($("div3").style.height);
$("div3").innerHTML="3"; $("div4").style.width="100px";
$("div4").style.height="100px";
$("div4").style.left=document.body.clientWidth-parseInt($("div4").style.width);
$("div4").style.top=document.body.clientHeight-parseInt($("div4").style.height);
$("div4").innerHTML="4";
}
var arr=new Array();
document.onmousedown=function(event){validate(event)};
window.onresize=initialize;
function validate(e)
{
e=e||event;
if(e.clientX>parseInt($("div1").style.left)
&& e.clientX<parseInt($("div1").style.left)+parseInt($("div1").style.width)
&& e.clientY>parseInt($("div1").style.top)
&& e.clientY<parseInt($("div1").style.top)+parseInt($("div1").style.height))
{
arr.push(1);
}
else if(e.clientX>parseInt($("div2").style.left)
&& e.clientX<parseInt($("div2").style.left)+parseInt($("div2").style.width)
&& e.clientY>parseInt($("div2").style.top)
&& e.clientY<parseInt($("div2").style.top)+parseInt($("div2").style.height))
{
arr.push(2);
}
else if(e.clientX>parseInt($("div3").style.left)
&& e.clientX<parseInt($("div3").style.left)+parseInt($("div3").style.width)
&& e.clientY>parseInt($("div3").style.top)
&& e.clientY<parseInt($("div3").style.top)+parseInt($("div3").style.height))
{
arr.push(3);
}
else if(e.clientX>parseInt($("div4").style.left)
&& e.clientX<parseInt($("div4").style.left)+parseInt($("div4").style.width)
&& e.clientY>parseInt($("div4").style.top)
&& e.clientY<parseInt($("div4").style.top)+parseInt($("div4").style.height))
{
arr.push(4);
}
else
{
arr.length=0;
}
if(arr.length==4 && arr[0]==1 && arr[1]==2 && arr[2]==3 && arr[3]==4)
{
doSomething();
}
}; function doSomething()
{
alert("Congratulate to next stage!");
}; </script>
</head>
<body onload="initialize()">
<div id="div1"></div>
<div id="div2"></div>
<div id="div3"></div>
<div id="div4"></div>
</body>
</html>
你按1,2,3,4的顺序点就可以看到效果,点错了可以点空白区域重置。