Jquery 无法在母版页中工作
当我运行以下代码时,出现错误 意外字符“$”
当我单独运行它时,它运行成功,但当我通过母版页运行它时,它运行不成功。这是我的母版页代码:
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs"
Inherits="SwordBugTrackingSystem.SiteMaster" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head runat="server">
<title></title>
<link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="/Scripts/jquery-1.3.2.min.js" runat="server">
</script>
<script type="text/javascript" src="/Scripts/cal.js" runat="server" ></script>
<script type="text/javascript">
jQuery(document).ready(function () {
$('input.one').simpleDatepicker();
});
</script>
<asp:ContentPlaceHolder ID="HeadContent" runat="server">
</asp:ContentPlaceHolder>
</head>
这是我的 aspx 页面:
<%@ Page Title="About Us" Language="C#" MasterPageFile="~/Site.master"
AutoEventWireup="true" CodeBehind="About.aspx.cs"
Inherits="SwordBugTrackingSystem.About" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<h2>
About
</h2>
<p>Some test inputs, each with a different setup:</p>
<p><input class="one" type="text" name="date" value="" runat="server"/>
</asp:Content>
When I run the following code, i get the error Unexpected character '$'
It runs sucessfully when I run it indvidually but when i run it via Master page it doesnt. Here's my Master Page code:
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs"
Inherits="SwordBugTrackingSystem.SiteMaster" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head runat="server">
<title></title>
<link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="/Scripts/jquery-1.3.2.min.js" runat="server">
</script>
<script type="text/javascript" src="/Scripts/cal.js" runat="server" ></script>
<script type="text/javascript">
jQuery(document).ready(function () {
$('input.one').simpleDatepicker();
});
</script>
<asp:ContentPlaceHolder ID="HeadContent" runat="server">
</asp:ContentPlaceHolder>
</head>
Here is my aspx page:
<%@ Page Title="About Us" Language="C#" MasterPageFile="~/Site.master"
AutoEventWireup="true" CodeBehind="About.aspx.cs"
Inherits="SwordBugTrackingSystem.About" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<h2>
About
</h2>
<p>Some test inputs, each with a different setup:</p>
<p><input class="one" type="text" name="date" value="" runat="server"/>
</asp:Content>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不能将客户端脚本标记为 runat="server",asp.net 会尝试将其编译为 c#/vb 或您的页面设置的任何语言。将其删除即可工作。
You can't have client side script marked as runat="server", asp.net will try and compile it as c#/vb or whatever language your page is set to. Remove it and it will work.
我要检查的第一件事是 jQuery 的相对路径是否正确。
如果您的 Site.css 样式表加载正确,那么您可能需要使用波浪号引用 jQuery 文件
~/Scripts/jquery-1.3.2.min.js
The first thing I would check to see is if the relative path is correct for jQuery.
If your Site.css stylesheet is loading properly then you probably need to reference the jQuery file with the tilde
~/Scripts/jquery-1.3.2.min.js