JavaScript 未按预期工作 [英] JavaScript not working as expected

查看:58
本文介绍了JavaScript 未按预期工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的 VC++ 程序中绘制漂亮的图表,所以决定用 HTML 和 JavaScript 来实现.

I want to draw chart that is beautiful in my VC++ program and so decided to implement in by HTML and JavaScript.

正如它显示的那样,我下载了一个 Javascript 库并按照其网站上的说明使用它.
如何使用?

As it show, I downloaded a Javascript lib and used it as it said in its site.
How to use it?

下载 raphael.js 并将其包含到您的 HTML 页面中,然后像这样简单地使用它:

// Creates canvas 320 × 200 at 10, 50
var paper = Raphael(10, 50, 320, 200);

// Creates circle at x = 50, y = 40, with radius 10
var circle = paper.circle(50, 40, 10);

// Sets the fill attribute of the circle to red (#f00)
circle.attr("fill", "#f00");

// Sets the stroke attribute of the circle to white    
circle.attr("stroke", "#fff");

我包含了如下所示的 javascript 文件:

I included javascript file like below:

<head>
<script type="text/javascript" src="raphael.js"></script>
<script type="text/javascript">
ABOVE CODE
</script>

如果你试一试,那是行不通的.我试图让它工作,但不能.我有个问题.如果不从演示的另存为页面复制内容,我该如何工作?当然,它包括文档,但它是参考.

If you try it, it won't work. I tried to make it work, but could not. I have a question. How can I do it work without copying things from save as page of their demo? Of course, it includes documentation, but it is reference.

它是如何简单地工作的?谢谢!

How does it work simply? Thanks!

推荐答案

检查对 Raphael 库的引用,然后试试这个代码:

Check the reference to the Raphael library, and then try this code:

<head>
  <script type='text/javascript' src='raphael.js'></script>

  <script type='text/javascript'>
  //<![CDATA[ 
  window.onload=function(){
    // Creates canvas 320 × 200 at 10, 50
    var paper = Raphael(10, 50, 320, 200);

    // Creates circle at x = 50, y = 40, with radius 10
    var circle = paper.circle(50, 40, 10);
    // Sets the fill attribute of the circle to red (#f00)
    circle.attr("fill", "#f00");

    // Sets the stroke attribute of the circle to white    
    circle.attr("stroke", "#fff");
  }
  //]]> 
  </script>
</head>

这对我有用,请确保您的参考是好的.

This works for me, make sure your reference is good.

JSFiddle

这篇关于JavaScript 未按预期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆