Home  >  Article  >  Web Front-end  >  用图片作为label,for属性IE下不起作用 _HTML/Xhtml_网页制作

用图片作为label,for属性IE下不起作用 _HTML/Xhtml_网页制作

WBOY
WBOYOriginal
2016-05-16 16:41:421381browse

例如:

复制代码
代码如下:



我们希望得到的效果是:点击“中国银行”,复选框会被选上(或者取消)。在FireFox,CHROME等浏览器下是没有问题的,但是IE浏览器却不吃这套。

解决的办法是使用JS:

复制代码
代码如下:

window.onload = function(){
if(document.all && navigator.appVersion.indexOf("MSIE")>-1 && navigator.appVersion.indexOf("Windows")>-1)
{
var a = document.getElementsByTagName("label");
for(var i=0,j=a.length;iif(a[i].hasChildNodes && a[i].childNodes.item(0).tagName == "IMG")
{
a[i].childNodes.item(0).forid = a[i].htmlFor;
a[i].childNodes.item(0).onclick = function(){
var e = document.getElementById(this.forid);
switch(e.type){
case "radio": e.checked|=1;break;
case "checkbox": e.checked=!e.checked;break;
case "text": case "password": case "textarea": e.focus(); break;
}
}
}
}
}
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn