源代码
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<body><!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<body>
<div id="div1">
<img src="images/icont-1.png"/>
<img src="images/icont-2.png"/>
<img src="images/icont-3.png"/>
<img src="images/icont-4.png"/>
<img src="images/icont-5.png"/>
<img src="images/icont-6.png"/>
<img src="images/icont-7.png"/>
<img src="images/icont-8.png"/>
</div>
</body>
<script type="text/javascript">
window.onload=function(){
var images=document.getElementsByTagName("img");
for(var i=0; i<images.length; i++){
var image=images[i];
if(image.addEventListener){
image.addEventListener("click",hide,false);
}else{
image.attachEvent("onclick",hide);
}
}
function hide(event){
event.target.style.visibility="hidden";
}
}
</script>
</html>
</body>
</html>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<body><!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<body>
<div id="div1">
<img src="images/icont-1.png"/>
<img src="images/icont-2.png"/>
<img src="images/icont-3.png"/>
<img src="images/icont-4.png"/>
<img src="images/icont-5.png"/>
<img src="images/icont-6.png"/>
<img src="images/icont-7.png"/>
<img src="images/icont-8.png"/>
</div>
</body>
<script type="text/javascript">
window.onload=function(){
var images=document.getElementsByTagName("img");
for(var i=0; i<images.length; i++){
var image=images[i];
if(image.addEventListener){
image.addEventListener("click",hide,false);
}else{
//image.attachEvent("onclick",hide);
image.onclick=function(evt){
var evt = window.event;
var src = evt.srcElement || evt.target;
src.style.visibility="hidden";
}
}
}
function hide(event){
event.target.style.visibility="hidden";
}
}
</script>
</html>
</body>
</html>
稍作修改后可以都兼容了,现在想不动else{},而是去修改hide这个函数来实现兼容
Img.prototype.hide=function(event){
}
还有其他办法吗