1

我有这样的代码

<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') ;
}

如果我从复选框标记中删除类属性,我的 JS 函数就会调用。我只想在不删除类属性的情况下调用该函数。我从 SO 那里得到了一种解决方案,只需将文档类型更改为

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

请提供正确的方法来克服。

4

1 回答 1

0

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

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

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;
}

替换显示:无;在您的代码中声明

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

于 2013-06-21T15:32:33.160 回答