我是javascript的新手。
我尝试在Asp.net Mvc中使用Html.Dropdownlist。
我有1个下拉列表和其他4个下拉列表。
如果1.dropdownlist更改值,我想通过在JavaScript中使用foreach为4个dropdownlists应用1.dropdownlist值。
HTML:
@Html.DropDownList("MainDropDownList", listItems, "Select", new { @id = "MainDropDownListID" })
// İf this dropdownlist value changes , i want to apply value to other dropdownlists.
<table>
<tr>
<td>@Html.DropDownList("MyDropDownList1", listItems)</td>
<td>@Html.DropDownList("MyDropDownList2", listItems)</td>
<td>@Html.DropDownList("MyDropDownList3", listItems)</td>
<td>@Html.DropDownList("MyDropDownList4", listItems)</td>
</tr>
</table>
Javascript:
$(function () {
$('select#MainDropDownListID').change(function () {
var SelectedValue = $(this).val();
//How can i apply selectedvalue to 4 dropdownlists value using foreach ?
});
});
参考方案
jQuery的.val()
函数也可以用于set a value by supplying the value as an argument:
$('#MainDropDownListID').change(function () {
var SelectedValue = $(this).val();
$('table select').val(SelectedValue);
});
HTML Action ID获取方法 - javascript这可能已经是另一个问题的副本,但我找不到它。我采取了以下行动:<form id="bug-form" action="/AST_14/Bugg.ly2/index.php/bug/update/" method="post"> 现在,我的系统的工作方式是每个需要更新的“错误”都有自己的错…
html onClick打开url存储在php变量中 - javascript以下是我的代码,正在获取Uncaught SyntaxError: Unexpected token },但是我的代码中没有看到任何}。 window.open期望用引号引起来的url,我尝试了单引号和双引号的不同组合,但不起作用并且也无法在echo中转义双引号。请帮助谢谢..<?php $a = "https://www.google.co…
html | textarea中的额外标签 - javascript我正在尝试将Markdown从数据库加载到textarea:<textarea class="wmd-input" id="wmd-input" name="question" required="required"> <?php echo '**Th…
是否可以向@ Html.ActionLink参数添加动态值 - javascript我的MVC控制器中有一个方法,该方法在调用时会下载一个文档。我有一个引导程序模式,href驻留在其中,它指向此方法。@Html.ActionLink("Download", "Download", new { applicantId = 1, templateId = 1 }) 分钟的applicantId和templ…
使用只读属性设置输入字段的默认值 - javascript我有一种将持久性数据发布到SQL数据库的表单。在我的表单中,我首先将输入字段设置为只读,除非用户选择以下选项:我的问题是,如果用户选择不在输入字段中输入值,则会收到此错误:我尝试在JavaScript中设置输入的默认值,但收到相同的错误。$("#lejeperiode").val(" "); 向数据库中插入空字符串还是…