简体   繁体   English

Firefox在输入复选框上出现Javascript单击事件的问题

[英]Firefox issue with Javascript click event on input checkbox

I'm using some Jquery code to modify the style class of a label that is related with the input being clicked. 我正在使用一些Jquery代码来修改与单击的输入相关的标签的样式类。 So to do that, I'm using the ui-state-active class added by primefaces, something like this: 因此,我使用的是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
});

I know the code is kind of complex, but I had to do it like this because of the way primefaces renders it. 我知道代码有点复杂,但是由于素数渲染它的方式,我不得不这样做。 The thing is, most of browsers like chrome, IE10, and even firefox just with the input[type='radio'] work like this: once the input is clicked, the class ui-state-active is added, and then the javascript click event is called, so my code works perfectly this way. 事实是,大多数浏览器(例如chrome,IE10甚至是firefox)仅具有input[type='radio']工作方式如下:单击输入后,将添加ui-state-active类,然后添加javascript click事件被调用,因此我的代码以这种方式完美运行。 But is happening to me that, just in firefox and just with the input[type='checkbox'] is working the other way around, ie is calling the click event first and then is adding the class ui-state-active , which makes my code fail. 但是发生在我身上的是,仅在firefox中,并且仅与input[type='checkbox']一起工作,即首先调用click事件,然后添加ui-state-active ,这使得我的代码失败。 Is this a firefox bug? 这是Firefox的错误吗? or a problem with my code? 还是我的代码有问题? how can I solve it? 我该如何解决? Thanks. 谢谢。

PD: Tested with latest firefox version: 30.0 PD:已测试最新的Firefox版本:30.0

I'm temporarily solving it using if ($.browser.mozilla) { to add the needed behavior when the browser is firefox. 我暂时使用if ($.browser.mozilla) {解决该问题,以在浏览器为Firefox时添加所需的行为。 Although I'm still looking for a more stylish solution. 尽管我仍在寻找更时尚的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM