尝试调用jQuery时为什么会出现"Error:object expected"?

Cli*_*ash 0 vb.net asp.net

代码生成"预期的错误对象":

<script type ="text/javascript" >
    var doRedirect = function() { location.href='http://www.google.com' };
    $("#<%=Button1.ClientId%>").click(function() {
        $("#<%=Label1.ClientId%>").show();
        window.setTimeout("$('#<%=Label1.ClientId%>').fadeOut('slow', doRedirect)", 10000);
    });
    </script>
Run Code Online (Sandbox Code Playgroud)

这段代码有什么问题?

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div style="color: #009933; font-weight: 700">

        <asp:Button ID="Button1" runat="server" Text="Button" />

    </div>
    <p style="color: #336600; font-weight: 700">
        <asp:Label ID="Label1" runat="server" Text="Label" Visible="False"></asp:Label>
    </p>
    </form>
     <script type ="text/javascript" >
         var doRedirect = function() { location.href='http://www.google.com' };
         $("#<%=Button1.ClientId%>").click(function() {
             $("#<%=Label1.ClientId%>").show();
             window.setTimeout("$('#<%=Label1.ClientId%>').fadeOut('slow', doRedirect)", 10000);
         });
     </script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

dje*_*eeg 6

您可能需要在您的内部包含一个jQuery引用 <head>

<script src="javascript/jquery-1.3.2.min.js" type="text/javascript"></script>
Run Code Online (Sandbox Code Playgroud)

http://www.ajaxprojects.com/ajax/tutorialdetails.php?itemid=609