单选按钮值没有第二次改变
Radio button value is not changing for second time
我有 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")
我有 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")