【问题标题】:Failed to clone iCheck Box克隆 iCheck Box 失败
【发布时间】:2014-11-17 11:22:58
【问题描述】:

拥有使用 iCheck 插件的检查员列表。

<li>
   <input id="unique_id" name="request[accounts][0][advantages][swops]" type="checkbox" value="1" tabindex="34">
   <label for="unique_id">Some Text</label>
</li>

并且在 jQuery File 中是以下脚本

$(document).ready(function(){
    $('input').iCheck({
        checkboxClass: 'icheckbox_square-green',
    });
});

页面加载后变成这样:

<li>
    <div class="icheckbox_square-green" aria-checked="false" aria-disabled="false" style="position: relative;">
        <input id="unique_id" name="request[accounts][0][advantages][swops]" type="checkbox" value="1" tabindex="34" style="position: absolute; opacity: 0;">
        <ins class="iCheck-helper" style="position: absolute; top: 0%; left: 0%; display: block; width: 100%; height: 100%; margin: 0px; padding: 0px; border: 0px; opacity: 0; background: rgb(255, 255, 255);"></ins>
    </div>
    <label for="unique_id" class="">Swops</label>
</li>

当我克隆时

var add_id = 1;
$('.js-clone-account').click(function() {
var $new_form_block = $('.field_set_class').clone().prop('class', 'reply'+add_id);

$new_form_block.clearMyForm(); // Clears all input values

$new_form_block.find('#unique_id').prop('id', 'unique_id'+add_id).prop('name', 'old_name'+add_id);
$new_form_block.find('#unique_id'+add_id).next().prop('for', 'unique_id'+add_id);

$new_form_block.appendTo("#other_div");
            add_id = add_id + 1;
        });

问题 OnClick 正在克隆所有元素,但复选框不再起作用。并且标签的 id 没有添加一个,这是因为添加了 div 标签和 ins 标签。在简单的复选框.clone 上工作。任何想法都会非常有帮助。

【问题讨论】:

标签: jquery icheck


【解决方案1】:

在你的克隆中使用这种方式:

$('#div_to_clone').find('.checkbox_container').html( < input type='checkbox' 
    class='checkbox_class' name='chechbox_name'  value='1' > );<br>
$('.contrainer .checkbox_class').iCheck({
    checkboxClass: 'icheckbox_flat-green',
    increaseArea: '20%'
});

在你触发ifChecked 的地方使用这种类型的语法来调用它:

$('#container_id').on('ifChecked','.checkbox_class', function (event){  

}); 

【讨论】:

    猜你喜欢
    • 2013-04-16
    • 2011-06-11
    • 1970-01-01
    • 2017-07-28
    • 2014-09-08
    • 2016-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多