2016-12-13 50 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

相關問題