2016-12-13 105 views
0

我使用icheck.js作为单选按钮和复选框。当我现在使用它们时,它打破了我的表单过去的工作方式。我有一个复选框,当检查它应该显示一个表单,但现在当我检查它没有发生任何事情。 (也许是因为实际的复选框它自身没有被选中)当使用icheck选中复选框时显示表单,js

http://jsfiddle.net/75qmj037/6/

与显示选中该复选框,当我的形式任何帮助将不胜感激!

<div class="row"> 
    <div class="col-lg-12"> 
     <div class="form-group i-checks"> 
      <input type="checkbox" name="anotherSeller1" id="anotherSeller1" onchange="valueChanged1()" /> 
      <em>Check this box if there is another seller.</em> 
     </div> 
    </div> 
</div> 

<div name="Form2" id="Form2" style="display: none;"> 
test 
</div> 

JS

jQuery('input').iCheck({ 
    checkboxClass: 'icheckbox_square-blue', 
    radioClass: 'iradio_square-blue', 
    increaseArea: '20%' // optional 
}); 


function valueChanged1() 
{ 
    if($('#anotherSeller1').is(":checked")) 
     $("#Form2").show(); 
    else 
     $("#Form2").hide(); 
     $("#Form2 > .clearfix input:text").val(""); 
     $("#Form2 > select").val(""); 
     $("#anotherSeller2").prop("checked", false); 
     $("#Form3").hide(); 
     $("#Form3 > .clearfix input:text").val(""); 
     $("#Form3 > select").val(""); 
     $("#anotherSeller3").prop("checked", false); 
     $("#Form4").hide(); 
     $("#Form4 > .clearfix input:text").val(""); 
     $("#Form4 > select").val(""); 
     $("#anotherSeller4").prop("checked", false); 
     $("#Form5").hide(); 
     $("#Form5 > .clearfix input:text").val(""); 
     $("#Form5 > select").val(""); 

} 

回答

1

看起来这个插件实际上并没有选中/取消选中该复选框,它只是让自己的状态。那真不幸。要解决此问题,请使用它们提供的事件:

jQuery('input').iCheck({ 
    checkboxClass: 'icheckbox_square-blue', 
    radioClass: 'iradio_square-blue', 
    increaseArea: '20%' // optional 
}).on('ifChanged', valueChanged1); 

将事件处理程序添加到最终使其工作。或者,不要使用插件,只需使用CSS自定义插件。

注意:我还会换出<em><label>,如果整行处于活动状态,单击复选框会更容易。

+0

感谢您的帮助!让我知道如果这将是你可以弄清楚的东西http://stackoverflow.com/questions/41125795/icheck-js-radio-button-automatically-gets-checked-when-tabbing-32-through-form –

+0

可以你告诉我如何做一个特定的功能,我不能让另一个工作,因为功能是奇怪的 –

+0

我不知道你在问什么。您可以将侦听器更改为使用任何JS函数,只要它在作用域中并且在将其添加为处理程序之前存在。 – mherzig

相关问题