请参阅我的_Layout.cshtml
代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>@ViewBag.Title - My ASP.NET MVC Application</title>
<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<meta name="viewport" content="width=device-width" />
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
</head>
<body>
<header>
<div class="content-wrapper">
<div class="float-left">
<p class="site-title">@Html.ActionLink("your logo here", "Index", "Home")</p>
</div>
<div class="float-right">
<section id="login">
@Html.Partial("_LoginPartial")
</section>
<nav>
<ul id="menu">
<li>@Html.ActionLink("Home", "Index", "Home")</li>
<li>@Html.ActionLink("About", "About", "Home")</li>
<li>@Html.ActionLink("Contact", "Contact", "Home")</li>
</ul>
</nav>
</div>
</div>
</header>
<div id="body">
@RenderSection("featured", required: false)
<section class="content-wrapper main-content clear-fix">
@RenderBody()
</section>
</div>
<footer>
<div class="content-wrapper">
<div class="float-left">
<p>© @DateTime.Now.Year - My ASP.NET MVC Application</p>
</div>
</div>
</footer>
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryui")
@Styles.Render("~/Content/themes/base/css")
@RenderSection("scripts", required: false)
</body>
</html>
我检查firebug net tab并看到所有js文件都已下载到客户端PC但仍然jquery相关没有功能正在运行。
这是第一个显示警报,只是点击不起作用的按钮
$(function () {
$("#submit1").click(function () {
alert("button");
});
$(".datePicker").datepicker({
showOn: "button",
buttonImage: "/images/calendar-icon.png",
buttonImageOnly: true,
buttonText: "Select date"
});
});
单击按钮时,警报未显示。
日期选择器未来。
我犯了错误。请帮我整理一下。我错过了要包含的文件吗?感谢
我的view.cshtml代码如下
@model MvcApplication1.Controllers.Employee
<div class="editor-label">
@Html.LabelFor(model => model.Id)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Id)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Name)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Name)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Salary)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Salary)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.IsMale)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.IsMale)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.JoinDate)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.JoinDate, new { @class = "datePicker" })
</div>
<script>
$(function () {
$(".datePicker").datepicker({
showOn: "button",
buttonImage: "/images/calendar-icon.png",
buttonImageOnly: true,
buttonText: "Select date"
});
});
</script>
答案 0 :(得分:1)
或改变 @ Html.EditorFor(model =&gt; model.JoinDate,new {@class =&#34; datePicker&#34;}) 至 @ Html.TextBoxFor(model =&gt; model.JoinDate,new {@class =&#34; datePicker&#34;})
答案 1 :(得分:0)
假设您的View.cshtml是在@RenderBody中呈现的页面,您需要在View.cshtml的一个部分中引用您的脚本,如下所示:
@section Scripts {
@Scripts.Render("~/Scripts/app/myscript.js")
}
这是JS工作的一个例子(你有正确的):https://jsfiddle.net/emonrc9c/