【发布时间】:2014-06-26 03:53:04
【问题描述】:
我正在使用一些 Jquery 代码来修改与单击的输入相关的标签的样式类。为此,我使用了 primefaces 添加的 ui-state-active 类,如下所示:
$("input[type='checkbox']").click( function() {
$(this).toggleClass("clicked"); //Just to have a reference of the component being clicked
if ($("div:has(.clicked) + div").hasClass("ui-state-active")) {
addSelected(compo); //Add class to the label related with the input
} else {
rmvSelected(compo); //Remove class to the label related with the input
}
$(this).toggleClass("clicked");
});
$("input[type='radio']").click( function() {
//same
});
我知道代码有点复杂,但由于 primefaces 呈现它的方式,我不得不这样做。问题是,大多数浏览器(如 chrome、IE10 甚至 firefox)都只有 input[type='radio'] 的工作方式如下:单击输入后,添加 ui-state-active 类,然后调用 javascript click 事件,所以我的代码以这种方式完美运行。但是发生在我身上的是,只是在 Firefox 中,而 input[type='checkbox'] 正在以相反的方式工作,即首先调用点击事件,然后添加类 ui-state-active,这使我的代码失败。这是Firefox的错误吗?还是我的代码有问题?我该如何解决?谢谢。
PD:使用最新的 Firefox 版本测试:30.0
【问题讨论】:
-
你能设置成 jsFiddle 并复制问题吗?
-
你在使用哪个复选框
p:selectBooleanCheckbox或h:selectBooleanCheckbox? -
p:selectManyCheckbox
标签: javascript jquery firefox primefaces