【发布时间】:2013-05-28 15:16:41
【问题描述】:
我正在使用 C# 和 SQL Server 2005 开发一个 ASP .Net MVC 3 应用程序。
在一个视图中,我有两个下拉列表,它们从基础表中加载相同的值。
我想创建一个事件,从 DropDownList 2 中删除在 DropDwonList 1 中选择的项目。
这是代码:
<%:Html.Label("Poste :")%><%: Html.DropDownListFor(model => model.SelectedPoste, Model.PostesItems, new { @id = "poste" })%>
<%:Html.Label("Poste Suivant :")%><%: Html.DropDownListFor(model => model.PosteSuivantSelected, Model.NextPS, new { @id = "dd" })%>
所以根据上面的代码,当在'Poste'中选择该项目时,它的相似之处应该从'Poste Suivant'中删除。
这是我尝试的,但没有成功:
function test3() {
var dd = document.getElementById('dd');
var posteElement = document.getElementById('poste');
var currentIndexP = posteElement.selectedIndex;
var currentIndexD = dd.selectedIndex;
if (currentIndexP == currentIndexD) dd.removeChild(dd[currentIndex]);
}
我认为问题在于:因为我没有在下拉列表中定义“test3()”。
【问题讨论】:
标签: c# javascript visual-studio-2010 asp.net-mvc-3