Spring radiobutton jquery onchange函数不起作用?

时间:2017-09-05 18:10:43

标签: jquery html css spring jsp

我的js文件包含以下内容:

$('input[type=radio][name=paymentOption]:radio').change(function () {
    alert('something');
}

我的jsp包含以下html:

<label><form:radiobutton name="paymentOption" path="usePaypal"
   value="true" checked="checked"/>Paypal
</label>

<label><form:radiobutton name="paymentOption" path="usePaypal"
                                             value="false"/>Card
</label>

我尝试了很多css选择器,包括:

$("input[type=radio][name='paymentOption']").on("change", function () {}

任何人都可以查明我遇到的问题吗?

修改

对于那些有相同问题的人 - spring form标签要求css选择器中使用的名称是路径而不是名称,就像默认的html radiobuttons一样。

1 个答案:

答案 0 :(得分:0)

请致电以下

<script>

  $(document).ready(function(){
      $("input[type=radio][name=usePaypal]").change(function () {

            if ($(this).val() == "true") {
                alert('true');
            } else {
                alert('false');
            }
        });
  });

</script>
相关问题