微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

单选按钮的值第二次未更改

如何解决单选按钮的值第二次未更改

我有3个单选按钮,如下所示。

我要根据单选按钮的选择更改textBox1和textBox2的占位符。

            @Html.RadioButtonFor(model => model.Type,"feet")
            @Html.Label("feet ")
              
            @Html.RadioButtonFor(model => model.Type,"meter")
            @Html.Label("meter")
              
            @Html.RadioButtonFor(model => model.Type,"cm")
            @Html.Label("Centimeter")

javascrpt代码

  $(':radio[name=Type]').change(function () {        
        var value = $(this).val();
        var radiobutton= $(':radio[name=Type]:checked').val();
        $("#Type").val($(this).val());
        $("#textBox1").attr('placeholder',$(this).val())
        $("#textBox2").attr('placeholder',$(this).val())
  });

当我第一次单击单选按钮时,占位符将根据选定的单选按钮进行更改。

但是当我第二次单击第一个单选按钮(英尺)时,它的值没有改变,而其他单选按钮的值正在改变。

我需要在哪里进行更改?

谢谢。

解决方法

通过为单选按钮添加唯一ID解决问题

@Html.RadioButtonFor(model => model.Type,"feet",new { id = "feet" })
@Html.Label("feet ")
  
@Html.RadioButtonFor(model => model.Type,"meter",new { id = "meter" })
@Html.Label("meter")
  
@Html.RadioButtonFor(model => model.Type,"cm",new { id = "cm" })
@Html.Label("Centimeter")

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。