如何解决不兼容将 boostrap-datepicker 与 @Scripts.Render("~/bundles/jquery") 结合使用
我正在尝试在我的 asp.net-mvc 项目中实现一个输入日期选择器,它只显示创建/编辑模型新值的年份。我希望日期和月份始终相同(31/12/year)并允许用户仅选择年份。像这样:
为此,我使用了这里的代码:https://qawithexperts.com/article/bootstrap/select-only-year-in-bootstrap-datepicker/323
<link href="https://netdna.bootstrapcdn.com/bootstrap/2.3.2/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.2.0/css/datepicker.min.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/2.3.2/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.2.0/js/bootstrap-datepicker.min.js"></script>
<br />
<input type="text" class="form-control" name="datepicker" id="datepicker" />
<script>
$(document).ready(function(){
$("#datepicker").datepicker({
format: "yyyy",viewmode: "years",minviewmode: "years",autoclose:true
});
var dp = $("#datepicker").datepicker({
format: "yyyy",autoclose: true
});
//changeYear event trigger's
dp.on('changeYear',function (e) {
//do something here
alert("Year changed ");
});
})
在开始时,它不起作用:
但最近我找到了原因。在 _layout.cshtml 中,当您创建 asp.net-mvc 项目时,我有默认视图:
<!DOCTYPE html>
<html>
<head>
<Meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<Meta charset="utf-8" />
<Meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>@ViewBag.Title - Mi aplicación ASP.NET</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
@Html.ActionLink("Nombre de la aplicación","Index","Home",new { area = "" },new { @class = "navbar-brand" })
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>@Html.ActionLink("Inicio","Home")</li>
<li>@Html.ActionLink("Acerca de","About","Home")</li>
<li>@Html.ActionLink("Contacto","Contact","Home")</li>
</ul>
</div>
</div>
</div>
<div class="container body-content">
@RenderBody()
<hr />
<footer>
<p>© @DateTime.Now.Year - Mi aplicación ASP.NET</p>
</footer>
</div>
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts",required: false)
</body>
</html>
如果我删除它:@Scripts.Render("~/bundles/jquery")
它将起作用:
但我不确定删除它是否正确。所以我的问题是如何将“only-year boostrap-datepicker”与 @Scripts.Render("~/bundles/jquery")
一起使用,为什么会发生这种情况?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。