Html.RadioButton用于更改组外的其他单选按钮

时间:2017-04-12 11:32:45

标签: jquery razor

我有以下代码。没有预先选择的价值。我的问题是,我第一次点击radiobutton LocationID时,radiobutton TypeID具有相同的值而不是undefined ....为什么?你看错了吗?

 <div>
    <div class="col-lg-4 col-sm-4 col-xs-12 col-md-4 radio-reg">@Html.RadioButtonFor(m => m.TypeID, 1, new { onclick = "changeType()" })<span>Type1</span></div>
     <div class="col-lg-4 col-sm-4 col-xs-12 col-md-4 radio-reg">@Html.RadioButtonFor(m => m.TypeID, 2, new { onclick = "changeType()" })<span>Type2</span></div>
     <div class="col-lg-4 col-sm-4 col-xs-12 col-md-4 radio-reg">@Html.RadioButtonFor(m => m.TypeID, 3, new { onclick = "changeType()" })<span>Type3</span></div>
</div>  
<div>
    <div class="col-lg-4 col-sm-4 col-xs-12 col-md-4 radio-reg">@Html.RadioButtonFor(m => m.LocationID, 1, new { onclick = "changeLocation()" })<span>Location1</span></div>
     <div class="col-lg-4 col-sm-4 col-xs-12 col-md-4 radio-reg">@Html.RadioButtonFor(m => m.LocationID, 2, new { onclick = "changeLocation()" })<span>Location2</span></div>
   </div>  

使用Javascript:

function changeType() {
var type = $("input[name$='TypeID']:checked").val();          
var location = $("input[name$='LocationID']:checked").val();
console.log( type  + "-" + typeAdLocation);
}

function changeLocation() {
var type=  $("input[name$='TypeID']:checked").val();           
var location = $("input[name$='LocationID']:checked").val();  
console.log(type + "-" + location );
}

0 个答案:

没有答案