我寫了Asp.Net MVC應用程序,並且想要實現級聯下拉列表功能,但是我遇到了jQuery更改事件的問題。 我錯在哪裏?jQuery下拉列表更改事件不會觸發
的Javascript:
<script charset="utf-8" type="text/javascript" language="javascript" src="<%= Url.Content("~/Content/jquery-1.4.1.js") %>"></script>
<script charset="utf-8" type="text/javascript" language="javascript">
$(document).ready(function() {
$("#ddlCategories").change(function() { alert("It worked!"); });
});
</script>
MVC:
<%=Html.DropDownList("CategoriesId", (SelectList)ViewData["CategoriesList"], new { Id = "ddlCategories" })%>
<%=Html.DropDownList("ModelId", (SelectList)ViewData["ModelsList"], new { Id = "ddlModels" })%>
HTML:
<select name="CategoriesId" id="ddlCategories">
<option value="1">Thermage Solta Medical</option>
<option value="2">Syneron</option>
<option value="59">Deka</option>
</select>
<select name="ModelId" id="ddlModels">
<option value="1">Thermage NXT RF</option>
<option value="2">Thermacool TC</option>
</select>
在firefox中檢查它可能拋出的任何錯誤 – iamserious 2011-04-14 10:31:39
該代碼是否正常,並且應該可以正常工作,但可能存在影響此代碼的其他因素 – iamserious 2011-04-14 10:44:08
我的示例http://blogs.msdn.com/b /rickandy/archive/2012/01/09/cascasding-dropdownlist-in-asp-net-mvc.aspx這樣做。另見http://www.asp.net/mvc/tutorials/javascript/working-with-the-dropdownlist-box-and-jquery/using-the-dropdownlist-helper-with-aspnet-mvc – RickAndMSFT 2012-03-31 18:51:18