我在html的head部分有这些简单的文件,就像这样----
<!DOCTYPE html>
<head>
<title></title>
<script src="~/Scripts/jquery-2.1.4.js"></script>
<script src="~/Scripts/jquery.unobtrusive-ajax.js"></script>
<script src="~/Scripts/City.js"></script>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js? sensor=false"></script>
</head>
在正文部分,我有这个简单的方法来打开点击功能的警告框:
<body>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<fieldset>
<legend>Enter the Project Details</legend>
<div class="editor-label">
@Html.LabelFor(model => model.City)
</div>
<div class="editor-field">
@if (ViewData.ContainsKey("City")) {
@Html.DropDownListFor(model => model.City, ViewData["City"] as List<SelectListItem>, new { style = "width:250px", @class = "DropDown1"})
@Html.ValidationMessageFor(model => model.City)
}
</div>
<script type="text/javascript">
$(document).ready(function() {
var map;
$("#City").click(function() {
$.get("City.js", function () {
var jsonObject = JSON.parse(data);
alert("Data : " + data);
});
});
});
</script>
我的city.js
文件位于ASP.Net MVC应用程序的UI层的Scripts文件夹中。现在我想知道为什么我的JS代码没有运行。
答案 0 :(得分:0)
你缺少一个结束标签}); ..把它放在最后
<script type="text/javascript">
$(document).ready(function() {
var map;
$("#City").click(function() {
$.get("City.js", function () {
var jsonObject = JSON.parse(data);
alert("Data : " + data);
}); // closing for $.get("City.js"
});// closing for $("#City").click
}); // closing for (document).ready
</script>