首页 > 解决方案 > reacting to radio buttons with jquery

问题描述

I'm searching for a possibility to react with jquery or js, when a radio button is selected. My html

<div class="row" id="options2">
    <div class="col-lg-6 col-md-12 col-sm-12 col-xs-6">
        <input id="delivery" type="radio" name="option2" class="icheck">Lieferung</input>
    </div>
    <div class="col-lg-6 col-md-12 col-sm-12 col-xs-6">
        <input id="takeaway" type="radio" name="option2" class="icheck">Abholung</input>
   </div>
</div>

I tried this solution

$("input[name='option2']").change(function(){
  console.log('test');
});

Are there other possibilities to achieve this?

标签: javascriptjqueryhtml

解决方案


呃,我错过了模板提供的icheck,下面的代码它可以工作。 https://github.com/fronteed/icheck

$('#delivery').on('ifChecked', function(event){
    alert(event.type + ' callback');
  });

推荐阅读