IE8:当设置类时,没有调用复选框onclick

时间:2013-04-23 10:58:07

标签: javascript html html5 xhtml xhtml-1.0-strict

我有这样的代码

<input type='checkbox' class='rating'  id="sample"    onclick='checkboxcheck(parameters)'  />
                    <label for="sample"></label>

和CSS:

.rating {
    display:none;
}
input[type="checkbox"] + label {
    width: 15px;
    height: 15px;
    display: inline-block;
    background-image:url('../images/white_small.png') ;
}

input[type="checkbox"] + label:hover {
    width: 15px;
    height: 15px;
    display: inline-block;
    background-image:url('../images/golden_small.png') ;

}

input[type=checkbox]:checked + label {
    width: 15px;
    height: 15px;
    display: inline-block;
    background-image:url('../images/golden_small.png') ;
}

如果我从checkbox标签中删除class属性,我的JS函数调用了。 我只是想在不删除class属性的情况下调用该函数。 我从SO获得了一个解决方案,这只是将doctype更改为

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

请告诉我正确的方法。

1 个答案:

答案 0 :(得分:0)

我可以建议修改你的方法吗?

您可以使用div来包装复选框而不是display:none;,而是使用它来显示或隐藏您的复选框。我怀疑你会想要一直隐藏它。

<强> HTML:

<div class="hideRating">
     <input type="checkbox" class="rating" id="sample" onclick="checkboxcheck('parameters')" />
</div>
<label for="sample"></label>

其他CSS:

.hideRating {
  width:0;
  height:0;
  overflow:hidden;
}
.showRating {
  width:auto;
  height:auto;
  overflow:visible;
}

替换display:none;代码中的声明

如果您需要一个JS / jQuery函数示例来更新<div />元素的类,请告诉我。