单选框,获取选中的值

基本收音机盒

  • Text
  • Text
  • iCheck转型

     <!-- iCheck output format 
  • Text
  • Text
  • -->

    如您所见,检查附加到div ..

      $(document).ready(function () { $('input').iCheck({ checkboxClass: 'icheckbox_square-orange', radioClass: 'iradio_square-orange', increaseArea: '20%' // optional }); $("li").on("click", "input", function () { var val = $(this).val(); //updateDataGrid(val); alert(val); }); }); 

    问题和描述

    在添加icheck插件之前,如果javascript代码正常工作, 我想知道如何在icheck插件中获得相同的结果。 它的简单,在无线电点击它将值存储在变量后,它进一步传递给函数。

    实例: http : //jsfiddle.net/9ypwjvt4/

    iCheck: http ://fronteed.com/iCheck/

    将处理程序附加到ifChanged事件:

     $('input').on('ifChecked', function(event){ alert($(this).val()); // alert value }); 

    有11种方法可以监听变化 :

    • ifClicked – 用户单击自定义输入或指定标签
    • ifChanged – 输入的选中,禁用或不确定状态已更改
    • ifChecked – 输入的状态更改为已选中
    • ifUnchecked – 已删除已检查状态
    • ifToggled – 输入的选中状态已更改
    • ifDisabled -input的状态更改为禁用
    • ifEnabled – 删除禁用状态
    • ifIndeterminate – 输入的状态更改为不确定
    • ifDeterminate – 删除不确定状态
    • ifCreatedinput – 只是自定义
    • ifDestroyed – 刚刚删除了自定义

    的jsfiddle

    尽量避免使用jquery。 您也可以使用以下代码;

     $('input').on('ifChecked', function(event){ alert(event.target.value); // alert value }); 

    用这个

     // Check #x $( "#x" ).prop( "checked", true ); // Uncheck #x $( "#x" ).prop( "checked", false ); 
     $('body').on('ifChecked','.icheck', function(){ //considering icheck is the class of your checkbox and it is getting generated dynamically });