如何使用jquery

时间:2015-11-14 06:03:32

标签: jquery radio-button onchange

HTML:

<div class="radio-list  ">
     <label class="radio-inline">
     <span class=""><input type="radio" name="data[Customer][service_type]" id="service_type" value="new" checked=""></span> NEW INSTALLATION </label>
     <label class="radio-inline">
     <span class="checked"><input type="radio" name="data[Customer][service_type]" id="service_type" value="repair"></span> SERVICE REPAIR </label>
  <label class="radio-inline">
  <span class="checked"><input type="radio" name="data[Customer][service_type]" id="service_type" value="cancel"></span> CANCEL SERVICE </label>
  <label class="radio-inline">
  <span class="checked"><input type="radio" name="data[Customer][service_type]" id="service_type" value="other"></span> OTHER SERVICE </label>
</div>

如何在<input type="radio" name="data[Customer][service_type]" id="service_type" value="cancel">上申请更改活动?

4 个答案:

答案 0 :(得分:8)

$(function(){

    $("input:radio[name='data[Customer][service_type]']").change(function(){
        var _val = $(this).val();
        console.log(_val);
    });

});

.change是您需要触发的事件。

See it here.

答案 1 :(得分:1)

使用on change事件。

&#13;
&#13;
$("[name='data[Customer][service_type]']").on("change", function (e) {
    console.log(this.value);
});
&#13;
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="radio-list  ">
    <label class="radio-inline"> <span class=""><input type="radio" name="data[Customer][service_type]" id="service_type" value="new" checked=""></span> NEW INSTALLATION</label>
    <label class="radio-inline"> <span class="checked"><input type="radio" name="data[Customer][service_type]" id="service_type" value="repair"></span> SERVICE REPAIR</label>
    <label class="radio-inline"> <span class="checked"><input type="radio" name="data[Customer][service_type]" id="service_type" value="cancel"></span> CANCEL SERVICE</label>
    <label class="radio-inline"> <span class="checked"><input type="radio" name="data[Customer][service_type]" id="service_type" value="other"></span> OTHER SERVICE</label>
</div>
&#13;
&#13;
&#13;

答案 2 :(得分:0)

我正在使用此代码

 <meta http-equiv="refresh" content="5; url=/admin"/>

和javascript功能代码

<div class="radio-list  ">
     <label class="radio-inline">
     <span class=""><input type="radio" name="data[Customer][service_type]" id="service_type" value="new" checked="" onclick="myFunction(this.value)"></span> NEW INSTALLATION </label>

</div>

答案 3 :(得分:0)

我已经尝试了上述所有代码,但对我来说,当动态生成单选按钮时,下面的代码有效。

$(document).ready(function () {
 
$(document).on("change","input[name='data[Customer][service_type]']" ,function() {
      console.log("radio changed");
  });
  });