【问题标题】:how to know when checking a radio button?如何知道何时检查单选按钮?
【发布时间】:2013-09-20 20:49:10
【问题描述】:

我正在制作一个应用程序,在单击某个 div 时使用jQuery.icheck 显示单选按钮,我想在检查其中一个按钮时采取某种操作,我正在使用 icheck 网站中列出的说明但没有得到我正在使用的代码:

var itemoptions=[],optionstring='', oi=0;

for(oi=0;oi<=oc-1;oi++) {
  itemoptions[oi]=$('menu').find($(".selected").text()).children().eq(si).children().eq(oi).prop('nodeName');
  optionstring=optionstring+'<input type="radio" name="iCheck"><p style="line-height:10px; font-size:15px;">'+(itemoptions[oi]).toString()+'</p>'
}

$('.item_block').on('click',function(){
$('input').iCheck('check');    // here's the line of code that is supposed to be used to check all of he icheck radio buttons 
$(this).addClass('flipped_item');
  $(this).flip({                              //flipping options
  direction:'lr',
  speed:250,
  content:"<div class='option_wrapper'>"+optionstring+"</div>",
  onEnd:function(){$('input').iCheck({
    checkboxClass: 'icheckbox_flat-yellow',
    radioClass: 'iradio_flat-yellow'
  });
})

【问题讨论】:

  • 对这个问题有点困惑。您绑定一个事件还是要更改按钮的某些内容?究竟是什么问题,你有什么尝试。带有标记示例的小提琴 (jsfiddle.net) 也会有所帮助。

标签: javascript jquery html radio-button icheck


【解决方案1】:

使用

document.getElementById("check1").checked=true

声明

【讨论】:

    【解决方案2】:

    如果我理解正确,并且您只是想在选中或取消选中该单选按钮时执行一项操作,则可以将其绑定到更改事件。

    $(this).flip({                         //flipping options
        direction:  'lr',
        speed:      250,
        content:    "<div class='option_wrapper'>"+optionstring+"</div>",
        onEnd:      function() {
                        $('input').iCheck({
                            checkboxClass: 'icheckbox_flat-yellow',
                            radioClass: 'iradio_flat-yellow'
                        });
                        $('input').change(function() {
                            if ($(this).is(':checked'))
                                // Do Stuff
                            else
                                // Do other stuff
                        });
                    }
    });
    

    【讨论】:

    • 没有给我任何回应
    • 您的问题可能是您在单选按钮实际附加到 DOM 之前调用了某些语句(如 .change 或 .iCheck)。我不熟悉这个翻转功能的作用,但我假设这就是 onEnd 所代表的。看看我更新的答案是否有效。
    猜你喜欢
    • 1970-01-01
    • 2012-03-08
    • 2017-03-19
    • 2014-04-09
    • 2013-01-23
    • 1970-01-01
    • 2019-09-18
    • 2019-05-29
    • 1970-01-01
    相关资源
    最近更新 更多