我正在尝试在ASP.NET上使用jQuery,实际上下面的代码运行完美!
<head runat="server">
<title></title>
<link rel="shortcut icon" href="favicon.ico"/>
<script src="Scripts/jquery-1.9.1.min.js"></script>
<script src="Scripts/jquery-ui-1.10.2.min.js"></script>
<link href="Content/themes/base/jquery-ui.css" rel="stylesheet" />
<link href="StyleSheet.css" rel="stylesheet" />
<script type="text/javascript">
$(function () {
$("#txtDateFrom").datepicker({ dateFormat: 'mm-dd-yy' })
});
$(function () {
$("#txtDateTo").datepicker({ dateFormat: 'mm-dd-yy' })
});
</script>
</head>
但如果我在Mater / Content页面ASP.NET上使用jQuery,则忽略jQuery。
母版页:
<head runat="server">
<title>asdf</title>
<script src="Scripts/jquery-1.9.1.min.js"></script>
<script src="Scripts/jquery-ui-1.10.2.min.js"></script>
<link href="Content/themes/base/jquery-ui.css" rel="stylesheet" />
<link rel="shortcut icon" href="favicon.ico"/>
<link href="StyleSheet.css" rel="stylesheet" />
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div runat="server" id="top_outer"></div>
<div runat="server" id="outer">
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
内容页面:
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<script type="text/javascript">
$(function () {
$("#txtDateFrom").datepicker({ dateFormat: 'mm-dd-yy' })
});
$(function () {
$("#txtDateTo").datepicker({ dateFormat: 'mm-dd-yy' })
});
</script>
</asp:Content>
有谁知道为什么?
修改 我从Chrome中的“查看页面源”获得了以下代码,当我检查javascript的每个链接时,该页面显示了javascript代码。我如何检查jQuery是否正确加载?
<head><title>
asdf
</title>
<script src="Scripts/jquery-1.9.1.min.js"></script>
<script src="Scripts/jquery-ui-1.10.2.min.js"></script>
<link href="Content/themes/base/jquery-ui.css" rel="stylesheet" /><link rel="shortcut icon" href="favicon.ico" /><link href="StyleSheet.css" rel="stylesheet" />
<script type="text/javascript">
$(function () {
$("#txtDateFrom").datepicker({ dateFormat: 'mm-dd-yy' })
});
$(function () {
$("#txtDateTo").datepicker({ dateFormat: 'mm-dd-yy' })
});
</script>
</head>
答案 0 :(得分:1)
我需要将“#txtDateFrom”更改为“#&lt;%= txtDateFrom.ClientID%&gt;”,现在工作正常!
<script type="text/javascript">
$(function () {
$("#<%=txtDateFrom.ClientID %>").datepicker({ dateFormat: 'mm-dd-yy' })
});
$(function () {
$("#<%=txtDateTo.ClientID %>").datepicker({ dateFormat: 'mm-dd-yy' })
});
</script>