发布网友 发布时间:2022-04-22 10:24
共3个回答
热心网友 时间:2022-04-25 02:03
//根据id查找元素
热心网友 时间:2022-04-25 03:21
<!DOCTYPE HTML>追问不循环!
追答<!DOCTYPE HTML>
<html>
<head>
<meta charset=UTF-8>
<title>recursion</title>
<style type="text/css">
div {
border: 1px solid black;
}
</style>
<script type="text/javascript" src="jquery-1.8.0.min.js"></script>
<script type="text/javascript">
window.onload = function ()
{
for ( var i = 10; i < 16; i += 2)
{
var dx = document.getElementById ("d" + i), dy = document.getElementById ("d" + (i + 1));
dx.index = i;
dx.onmouseover = function ()
{
document.getElementById ("d" + (this.index + 1)).style.display = "block";
};
dx.onmouseout = function ()
{
document.getElementById ("d" + (this.index + 1)).style.display = "none";
}
dy.onmouseover = function ()
{
this.style.display = "block";
};
dy.onmouseout = function ()
{
this.style.display = "none";
}
}
}
</script>
</head>
<body>
<div id="d10">10</div>
<div id="d11">11</div>
<div id="d12">12</div>
<div id="d13">13</div>
<div id="d14">14</div>
<div id="d15">15</div>
</body>
</html>
热心网友 时间:2022-04-25 04:56
用jQuery 写呗,循环都不用 $("#d10,#d11,#d12,...")或者使用其他选择器找到这些元素 在绑定具体的事件