拉斐尔没有使用jquery在asp.net页面上找到元素

问题描述

| 我是Raphael的新手,无法从现有元素创建Raphael对象。 下面的代码显示了我尝试过的内容以及每个人造成的错误。理想情况下,我想在首次调用Raphael时使用jquery创建对象。 任何帮助将非常感激。
<%@ Page Language=\"C#\" AutoEventWireup=\"true\" CodeBehind=\"WebForm2.aspx.cs\" Inherits=\"Fleetstar.UI.WebForm2\" %>
<!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\">
    <script src=\"js/raphael.js\" type=\"text/javascript\"></script>
    <script src=\"js/jquery.js\" type=\"text/javascript\"></script>
    <script type=\"text/javascript\">
    $(document).ready(function () {
        var thisWorks = document.getElementById(\'imgMap\');     // This works 
        var thisAlsoWorks = $(\'.mapClass\');          //thsi.works
        var thisDoeNotWorkA = Raphael(document.getElementById(\'imgMap\'),200,200);   //Error: Unexpected call to method or property access.
        var thisDoeNotWorkB = Raphael(document.getElementById(\'imgMap\')[0],200);  //Error: \'tagName\' is null or not an object
        var thisDoeNotWorkC = Raphael(document.getElementById(\'imgMap\').node,200);  //// Error: \'tagName\' is null or not an object
        var thisDoeNotWorkD = Raphael($(\'.mapClass\'),200);            //Error: \'container\' is null or not an object
        var thisDoeNotWorkE = Raphael($(\'.mapClass\').node,200);   // Error: \'tagName\' is null or not an object
        var thisDoeNotWorkF = Raphael($(\'.mapClass\')[0],200);    //Error: Unexpected call to method or property access.
        var thisDoeNotWorkG = Raphael($(\'[id$=\"imgMap\"]\'),200);    // Error: \'container\' is null or not an object
        var thisDoeNotWorkH = Raphael($(\'[id$=\"imgMap\"]\')[0],200);   //Error: Unexpected call to method or property access.
        var thisDoeNotWorkI = Raphael($(\'[id$=\"imgMap\"]\').node,200);   //Error: \'tagName\' is null or not an object

    });

</script>
</head>
<body>
  <form id=\"form1\" runat=\"server\">
<img class=\"mapClass\" id=\"imgMap\" name=\"imgMapName\" style=\"position: absolute\" src=\"Images/map.gif\"
    alt=\"\" />
</form>
    

解决方法

        尝试这个:
var thisDoeNotWorkA = Raphael(\'imgMap\',200,200);
http://raphaeljs.com/reference.html#Raphael上的规范说您要传递节点ID。 编辑:如果那不起作用,那么可能是元素ID被其他东西修改了吗?     ,        我从未见过有人尝试使用图像标签制作Raphael画布。 为什么不使用普通的div并将其放置在您喜欢的位置? thisDoesWork = Raphael(document.getElementById(\'imgMapDiv \'),200,200); 查尔斯 http://www.irunmywebsite.com     

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...