我真的在努力让一个简单的级联DropDown
工作。我正在做一个非常基本的示例,但它失败了。因此,我正试图深入了解基础知识,看看如何events
与controls
.
我有这个:
<script type="text/javascript">
$(document).ready(function() {
$('#CarMakeId').change(function () {
alert("khsdhf")
});
})
</script>
<html>
<head>
<title>Index</title>
</head>
<body>
<div>
Make: @Html.DropDownListFor(x=>x.CarMakeId,
new SelectList(Model.CarMakes, "Value", "Text"),
"-- select make --") <br />
Model: @Html.DropDownListFor(x=>x.CarModelId,
new SelectList(Model.CarModels, "Value", "Text"),
"-- select model --")
</div>
</body>
</html>
目前,我想要它做的就是在我更改下拉列表中的选择时提醒我。但我正在"Object expected
“进入Java Script
.
这是呈现的 HTML:
<!DOCTYPE html>
<script type="text/javascript">
$(document).ready(function () {
$('#CarMakeId').change(function () {
alert("khsdhf");
});
})
</script>
<html>
<head>
<title>Index</title>
</head>
<body>
<div>
<form action="/" method="post"> <p>
Make: <select data-val="true" data-val-number="The field CarMakeId must be a number." data-val-required="The CarMakeId field is required." id="CarMakeId" name="CarMakeId"><option value="">-- select make --</option>
<option value="1">BMW</option>
<option selected="selected" value="2">Ford</option>
<option value="3">Toyota</option>
</select>
<br />
Model: <select data-val="true" data-val-number="The field CarModelId must be a number." data-val-required="The CarModelId field is required." id="CarModelId" name="CarModelId"><option value="">-- select model --</option>
<option value="5">Mustang</option>
<option selected="selected" value="6">Territory</option>
<option value="7">Focus</option>
</select>
<br />
<input type="submit" name="Submit" title="Submit" />
</p>
</form> </div>
</body>
</html>
附加信息:
这给出了同样的错误:
<script type="text/javascript">
$(document).ready(function () {
alert("Hello");
})
</script>