在我的ASP.NET MVC视图中,我有一个下拉列表和三个单选按钮,如给定的
@Html.RadioButtonFor(m => m.ClientDur1.LookupValueID, "true", new { Name = "grp", @id = "CM1", @checked = "true" }) @Model.ClientDur1.Val1
@Html.RadioButtonFor(m => m.ClientDur2.LookupValueID, "false", new { Name = "grp", @id = "CM2" }) @Model.ClientDur2.Val1
@Html.RadioButtonFor(m => m.ClientDur3.LookupValueID, "false", new { Name = "grp", @id = "CM3" }) @Model.ClientDur3.Val3
我的下拉列表是,
@Html.DropDownListFor(m => m.Currency, new SelectList(Model.CurrencyList, "AttributeValueID", "AttributeDescription"), new { @id = "ddCurrencyId" })
我需要的是当我更改我的下拉列表时我想要更新我的单选按钮值,这是我的Model.ClientDur1.LookupValueID和ClientDur1.Val1(同样适用于其他人)应该有新的更改细节。< / p>
我怎样才能做到这一点?
答案 0 :(得分:1)
请尝试以下代码:
$(document).ready(function() {
$('#ddCurrencyId').change(function() {
$('#CM' + $(this).val()).trigger('click');
});
});
我真的需要看到更多HTML标记运行项目后看到单选按钮的值/ HTML ..
我猜测下拉列表的值将是1,2或3,这就是为什么我在代码中说SELECT the ID: CM + DropDownValue
..
答案 1 :(得分:1)
添加上面的答案:
试试这个JS小提琴http://jsfiddle.net/khoorooslary/6DjpT/
您需要使用Javascript将下拉列表的ID链接到输入广播
PS如果您不熟悉JSFiddle,请在右下方窗口查看演示并使用它
HTML代码
<form>
<input type="radio" id="rd_one" name="rd" value="1" checked="checked"/>
<input type="radio" id="rd_two" name="rd" value="2" />
<input type="radio" id="rd_three" name="rd" value="3" />
<input type="radio" id="rd_four" name="rd" value="4" />
<hr />
<select id="ByIdDemo">
<option>Select By Id Demo</option>
<option value="one">Option 1</option>
<option value="two">Option 2</option>
<option value="three">Option 3</option>
<option value="four">Option 4</option>
</select>
<hr />
<select id="ByValue">
<option>Select By Value Demo</option>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
<option value="4">Option 4</option>
</select>
</form>
Javascript代码
$(function() {
$("#ByIdDemo").on('change',function() {
var sel = this;
$("form input").each(function(eli,el) {
var id = "rd_"+ sel.options[sel.selectedIndex].value;
el.checked = el.id == id;
$(el).attr("checked", el.checked ? "checked" : null);
});
});
$("#ByValue").on('change',function() {
var sel = this;
$("form input").each(function(eli,el) {
el.checked = el.value == sel.options[sel.selectedIndex].value;
$(el).attr("checked", el.checked ? "checked" : null);
});
});
});