我正在尝试远程创建一个onclick
对于每个<div>
(以节省打字时间)。
这里是window.onload()
功能:
window.onload = function() {
divel = document.getElementsByTagName('div');
for (var el in divel) {
divel[el].onmouseover = function() {
this.style.textDecoration = "underline";
};
divel[el].onmouseout = function() {
this.style.textDecoration = "none";
};
divel[el].onclick = function() {
document.getElementById('game').src = "/games/" + this.name;
};
}
}
每个人的名字<div>
is "flyingsheep"
- 该值由以下设置<div name="flyingsheep">
.
当我点击<div>
, iframe"game"
带我到网页"/games/undefined"
.
这会起作用。问题已得到纠正。
只需使用:this.attributes["name"].value
window.onload = function() {
divel = document.getElementsByTagName('div');
for(var el in divel){
window.alert(divel[el].name);
divel[el].onmouseover = function(){ this.style.textDecoration = "underline"; };
divel[el].onmouseout = function(){ this.style.textDecoration = "none"; };
divel[el].onclick = function(){document.getElementById('game').src = this.attributes["name"].value;}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)