Raphael asp.net - Microsoft JScript 运行时错误:需要对象

发布于 2024-12-06 07:00:11 字数 1572 浏览 1 评论 0原文

我是 Raphael 和 asp.net 的新手。我正在尝试使用 asp.net 测试一个简单的 raphael 示例,但我不断收到以下错误: Microsoft JScript 运行时错误:对象预期

此错误发生在这一行:

var paper = Raphael("diii", 320, 200);

这是页面完整代码:

    <%@ Page Title="" Language="C#" MasterPageFile="~/Site.master"AutoEventWireup="true" CodeFile="Lingua.aspx.cs" Inherits="Lingua" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
    <script type="text/javascript" src="Scripts/raphael.js"></script>
    <script type="text/javascript" src="Scripts/jquery-1.4.1.js"></script>
    <script type="text/javascript">
function createCircle() {
    var paper = Raphael("diii", 320, 200);
    var circle = paper.circle(50, 40, 10);
    cicle.attr("fill", "#f00");
    circle.attr("stroke", "#fff");
}
    </script>
    <asp:GridView ID="GridView1" runat="server">
    </asp:GridView>
    <asp:DropDownList ID="DropDownList1" runat="server">
    <asp:ListItem Value="ger">one</asp:ListItem>
    <asp:ListItem Value="ara">two</asp:ListItem>
     </asp:DropDownList>
    <asp:Button ID="Button1" runat="server" onClientClick="return createCircle();" 
    Text="Add" />
    <div id="diii"></div>
    </asp:Content>

如果插入,则会发生相同的错误我使用上面提到的行:

var paper = Raphael(10,50,320,200);

有谁知道问题是什么?

I am new to Raphael, as well as asp.net. I am trying to test a simple raphael example with asp.net, but I keep geting the following error: Microsoft JScript runtime error: Object expected

this error occurs in this line:

var paper = Raphael("diii", 320, 200);

this is the page full code:

    <%@ Page Title="" Language="C#" MasterPageFile="~/Site.master"AutoEventWireup="true" CodeFile="Lingua.aspx.cs" Inherits="Lingua" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
    <script type="text/javascript" src="Scripts/raphael.js"></script>
    <script type="text/javascript" src="Scripts/jquery-1.4.1.js"></script>
    <script type="text/javascript">
function createCircle() {
    var paper = Raphael("diii", 320, 200);
    var circle = paper.circle(50, 40, 10);
    cicle.attr("fill", "#f00");
    circle.attr("stroke", "#fff");
}
    </script>
    <asp:GridView ID="GridView1" runat="server">
    </asp:GridView>
    <asp:DropDownList ID="DropDownList1" runat="server">
    <asp:ListItem Value="ger">one</asp:ListItem>
    <asp:ListItem Value="ara">two</asp:ListItem>
     </asp:DropDownList>
    <asp:Button ID="Button1" runat="server" onClientClick="return createCircle();" 
    Text="Add" />
    <div id="diii"></div>
    </asp:Content>

The same error occurs if insted of the mentioned line above I use:

var paper = Raphael(10,50,320,200);

Does anyone know what is the problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

天生の放荡 2024-12-13 07:00:11

您的代码中有两件事需要修复:

  1. 检查引用的 Rafeal js 文件的名称是什么。是 raphael-min.js 还是 raphael.js。
  2. 在您的代码中,您将“circle”错误地输入为“cicle”。更正它

您更正的代码在这里

    <%@ Page Title="" Language="C#" MasterPageFile="~/Site.master"AutoEventWireup="true" CodeFile="Lingua.aspx.cs" Inherits="Lingua" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<script type="text/javascript" src="Scripts/raphael-min.js"></script>
<script type="text/javascript" src="Scripts/jquery-1.4.1.js"></script>
<script type="text/javascript">
function createCircle() {
var paper = Raphael("diii", 320, 200);
var circle = paper.circle(50, 40, 10);
circle.attr("fill", "#f00");
circle.attr("stroke", "#fff");
}
</script>
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Value="ger">one</asp:ListItem>
<asp:ListItem Value="ara">two</asp:ListItem>
 </asp:DropDownList>
<asp:Button ID="Button1" runat="server" onClientClick="return createCircle();" 
Text="Add" />
<div id="diii"></div>
</asp:Content>

如果您想查看客户端副作用,请不要从服务器端按钮触发事件。

There are two things which need to be fix in your code

  1. Check what is name of referenced Rafeal js file. Is it raphael-min.js or raphael.js.
  2. In your code you mistype circle as cicle. correct it

Your corrected code is here

    <%@ Page Title="" Language="C#" MasterPageFile="~/Site.master"AutoEventWireup="true" CodeFile="Lingua.aspx.cs" Inherits="Lingua" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<script type="text/javascript" src="Scripts/raphael-min.js"></script>
<script type="text/javascript" src="Scripts/jquery-1.4.1.js"></script>
<script type="text/javascript">
function createCircle() {
var paper = Raphael("diii", 320, 200);
var circle = paper.circle(50, 40, 10);
circle.attr("fill", "#f00");
circle.attr("stroke", "#fff");
}
</script>
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Value="ger">one</asp:ListItem>
<asp:ListItem Value="ara">two</asp:ListItem>
 </asp:DropDownList>
<asp:Button ID="Button1" runat="server" onClientClick="return createCircle();" 
Text="Add" />
<div id="diii"></div>
</asp:Content>

If you want to see client side effects then do not trigger event from server side button.

厌味 2024-12-13 07:00:11

听起来您的 raphael.js 没有加载,您是否使用浏览器中的开发人员工具来检查所有脚本是否加载(没有 404 或 500)?

也尝试直接在浏览器中访问脚本的路径。

除此之外,我建议如下;

  1. 使用 jQuery 1.6.4(更好的支持,错误修复等)。
  2. 使用 jQuery Ready 函数确保页面在尝试调用之前已完成加载。

看起来您的脚本确实没有首先完全加载,因此将您的 js 代码替换为;

<script type="text/javascript">
    $(document).ready(function () {
        createCircle();
    });
    function createCircle() {
        var paper = Raphael("diii", 320, 200);
        var circle = paper.circle(50, 40, 10);
        cicle.attr("fill", "#f00");
        circle.attr("stroke", "#fff");
    }
</script>

It sounds like your raphael.js is not loading up, have you used the developer tools in your browser to check that all the scripts load (no 404s or 500s)?

Try accessing the scripts at their paths direct in the browser too.

Other than that, I would suggest the following;

  1. Use jQuery 1.6.4 (better supported, bug fixes etc).
  2. Use the jQuery ready function to make sure the page has finished loading before you have tried to call it.

It does look like your script is not loading fully first, so replace your js code with;

<script type="text/javascript">
    $(document).ready(function () {
        createCircle();
    });
    function createCircle() {
        var paper = Raphael("diii", 320, 200);
        var circle = paper.circle(50, 40, 10);
        cicle.attr("fill", "#f00");
        circle.attr("stroke", "#fff");
    }
</script>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文