如何动态添加onmouseover和onmouseout?在线等待。。。。 你说的自动生成<td></td>,是用什么形式来生成的? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 obj.onmouseover=function (){ this.style.backgroundColor='black';}obj.onmouseout=function (){ this.style.backgroundColor='white';} <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>setAttribute</title><style type="text/css">.tt { width:100px; height:50px; border:#666 1px solid; line-height:50px; text-align:center; background:#ff0;}.ttover { width:100px; height:50px; border:#666 1px solid; line-height:50px; text-align:center; background:#f00;}.ttout { width:100px; height:50px; border:#666 1px solid; line-height:50px; text-align:center; background:#ccc;}</style></head><body><div id="d1" class="tt">aaa</div><button onclick="xlh()">添加属性</button><script type="text/javascript" defer="defer"> var dd = document.getElementById("d1"); function xlh(){ dd.setAttribute("onmouseover",over); dd.setAttribute("onmouseout",out); } function over(){ dd.className = "ttover"; } function out(){ dd.className = "ttout"; }</script></body></html> js ascll码转为字符串 JS添加分类事件 如何给页面上的每一个链接增加声音事件 如何动态选中单选按钮 求助: 如何解决导航菜单被下拉选框遮盖住的问题 Jquery动态设置HTML问题 split 后,怎么得到数组的最大下标? 怎样通过网页上的按钮启动本地程序? 怎么样返回网页中被选中的文字,请大家进来一下 请教两个问题 mailto的问题 英文单词自动换行
this.style.backgroundColor='black';
}
obj.onmouseout=function (){
this.style.backgroundColor='white';
}
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>setAttribute</title>
<style type="text/css">
.tt {
width:100px;
height:50px;
border:#666 1px solid;
line-height:50px;
text-align:center;
background:#ff0;
}
.ttover {
width:100px;
height:50px;
border:#666 1px solid;
line-height:50px;
text-align:center;
background:#f00;
}
.ttout {
width:100px;
height:50px;
border:#666 1px solid;
line-height:50px;
text-align:center;
background:#ccc;
}
</style>
</head>
<body>
<div id="d1" class="tt">aaa</div>
<button onclick="xlh()">添加属性</button>
<script type="text/javascript" defer="defer">
var dd = document.getElementById("d1");
function xlh(){
dd.setAttribute("onmouseover",over);
dd.setAttribute("onmouseout",out);
}
function over(){
dd.className = "ttover";
}
function out(){
dd.className = "ttout";
}
</script>
</body>
</html>