我有一个网站,其中包含来自此链接的javascript文件: Code Snippet Page
我收到此错误:Microsoft JScript运行时错误:预期的对象
这是我的代码:
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="ATP_Assignment.Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="topArea" runat="server">
<div>
<div id="matchUp" class="floatLeft">
<div class="tabTop">
<div class="tabTL"></div>
<div class="tabTM">
<font class="title">Player Matchup History</font>
</div>
<div class="tabTR"></div>
</div>
<div class="tabMiddle">
<asp:DropDownList ID="ddlPlayer1" runat="server" Height="16px" Width="146px"
DataTextField="Name" DataValueField="Id">
</asp:DropDownList>
VS
<asp:DropDownList ID="ddlPlayer2" runat="server" Height="16px" Width="150px"
DataTextField="Name" DataValueField="ID">
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" Text="Click" onclick="Button1_Click" />
<br />
Player1: <asp:Label ID="lblPlayer1Score" Value="" runat="server"></asp:Label>
Player2: <asp:Label ID="lblPlayer2Score" Value="" runat="server"></asp:Label>
</div>
<div class="tabBottom">
<div class="tabBL"></div>
<div class="tabBM"></div>
<div class="tabBR"></div>
</div>
</div>
<div id="favList" class="floatLeft">
<div class="tabTop2">
<div class="tabTL"></div>
<div class="tabTM2">
<font class="title">Favorite Player List</font>
</div>
<div class="tabTR"></div>
</div>
<div class="tabMiddle2">
Enter Fav JQuery Here!!!
</div>
<div class="tabBottom2">
<div class="tabBL"></div>
<div class="tabBM2"></div>
<div class="tabBR"></div>
</div>
</div>
<div class="clearFix"> </div>
</div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="contentArea" runat="server">
<div class="padding">
<div>
<div id="playerList" class="floatLeft">
<font class="title">Player List</font>
<br />
<asp:DataList ID="PlayerList" runat="server">
<ItemTemplate>
Name:
<asp:Label ID="lblFirstName" runat="server"
Text='<%# Eval("FirstName") %>' />
<asp:Label ID="lblLastName" runat="server"
Text='<%# Eval("LastName") %>' />
<br />
Rank:
<asp:Label ID="lblRank" runat="server" Text='<%# Eval("Rank") %>' />
<br />
Country:
<asp:Label ID="lblCountry" runat="server" Text='<%# Eval("Country") %>' />
<br />
<br />
</ItemTemplate>
</asp:DataList>
</div>
<div class="smallPadding"> </div>
<div id="video">
</div>
<div class="clearFix"> </div>
</div>
<div id="tweet">
<font class="title">Recent Tweets</font>
<br />
<script type="text/javascript">
alert($ && $.fn ? $.fn.jquery : "jQuery not defined")
$(function () {
$("#favorites").tweet({
avatar_size: 32,
count: 3,
username: "atpworldtour",
favorites: true,
loading_text: "loading list..."
});
});
</script>
</div>
</div>
</asp:Content>
我应该把这段代码放在哪里:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js"></script>
答案 0 :(得分:2)
使用以下行在页面中包含jQuery和jQuery UI:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js"></script>
不使用:
<script runat="server" language="jscript"></script>
请记住,{em>服务器解释runat="server"
脚本,该脚本很可能已经在C#或VB.Net页面的上下文中。您想使用客户端脚本。
如果您希望本地脚本(例如,~/relative
链接),请考虑使用ScriptManager
。
答案 1 :(得分:0)
脚本标记需要进入Content1:
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js"></script>
</asp:Content>