当前位置: 首页 > 工具软件 > icheck > 使用案例 >

js使用iCheck插件监听获取CheckBox的值

汪飞捷
2023-12-01

HTML:

<tbody class="text-c tbody" id="tbody">
{foreach $order as $v}
	<tr class="info_tr " jwid="{$v.id}" tit="{$v.title}">
    	<td ><input id="is_show_{$v.id}" class="is_show" type="checkbox" name="is_show" {if condition="$v.is_show eq 1"}checked{/if} value="{$v.is_show}" eid="{$v.id}"></td>
     	<td>{$v.title}</td>
 	</tr>
{/foreach}
</tbody>

javascript:

$(".is_show").on('ifClicked', function(event){  
   // 这个地方取到的checked与实际相反,因为点击事件发生在真实变化之前,所以使用时要取反
    var multiSelect = event.target.checked ? 0 : 1;
    // console.log(event.target);
    // 根据选中修改value值
    if(multiSelect == 1){
        event.target.value = 1;
    }else{
        event.target.value = 0;
    }
});
 类似资料: