Javascript代码在asp.net中工作,但在从文件作为函数调用时不工作

Javascript代码在asp.net中工作,但在从文件作为函数调用时不工作,javascript,asp.net,Javascript,Asp.net,好的,我有一个d3.js的脚本,我从网上下载的 function draw() { var w = 600, h = 400, z = d3.scale.category20b(), i = 0; var svg = d3.select("div.container2").append("svg:svg") .attr("width", w) .attr("height", h)

好的,我有一个d3.js的脚本,我从网上下载的

function draw() {

    var w = 600,
        h = 400,
        z = d3.scale.category20b(),
        i = 0;

    var svg = d3.select("div.container2").append("svg:svg")
        .attr("width", w)
        .attr("height", h)
        .on("mousemove", particle);
}

function particle() {
    var m = d3.mouse(this);

    svg.append("svg:rect")
        .attr("x", m[0] - 10)
        .attr("y", m[1] - 10)
        .attr("height", 20)
        .attr("width", 20)
        .attr("rx", 10)
        .attr("ry", 10)
        .style("stroke", z(++i))
        .style("stroke-opacity", 1)
        .style("opacity", 0.7)
      .transition()
        .duration(5000)
        .ease(Math.sqrt)
        .attr("x", m[0] - 100)
        .attr("y", m[1] - 100)
        .attr("height", 200)
        .attr("width", 200)
        .style("stroke-opacity", 1e-6)
        .style("opacity", 1e-6)
        .remove();
}

The part of the asp.net that called the function is simply
<script src="js/d3Script.js"></script>        
    <script>        
        draw();
    </script>  
函数绘图(){
var w=600,
h=400,
z=d3.scale.category20b(),
i=0;
var svg=d3.select(“div.container2”).append(“svg:svg”)
.attr(“宽度”,w)
.attr(“高度”,h)
.on(“mousemove”,粒子);
}
函数粒子(){
var m=d3.鼠标(此);
append(“svg:rect”)
.attr(“x”,m[0]-10)
.attr(“y”,m[1]-10)
.attr(“高度”,20)
.attr(“宽度”,20)
.attr(“rx”,10)
.attr(“ry”,10)
.样式(“笔划”,z(++i))
.style(“笔划不透明度”,1)
.样式(“不透明度”,0.7)
.transition()
.持续时间(5000)
.ease(Math.sqrt)
.attr(“x”,m[0]-100)
.attr(“y”,m[1]-100)
.attr(“高度”,200)
.attr(“宽度”,200)
.样式(“笔划不透明度”,1e-6)
.样式(“不透明度”,1e-6)
.remove();
}
asp.net中调用该函数的部分只是
draw();
现在,当我用Java直接将draw函数替换为ASP页面时,它工作得很好。当我从js文件调用它时,它绘制画布,但什么也没发生

粒子函数被调用(我用警告进行了检查),但没有绘制任何内容。所需的所有其他js文件都已准备就绪

我是不是错过了一些简单的东西??谢谢

只需调用Javascript

    <script type="text/javascript">
     function draw() {

        var w = 600,
            h = 400,
            z = d3.scale.category20b(),
            i = 0;

        var svg = d3.select("div.container2").append("svg:svg")
            .attr("width", w)
            .attr("height", h)
            .on("mousemove", particle);
    }
   </script>

<script type="text/javascript">
function particle() {
        var m = d3.mouse(this);

        svg.append("svg:rect")
            .attr("x", m[0] - 10)
            .attr("y", m[1] - 10)
            .attr("height", 20)
            .attr("width", 20)
            .attr("rx", 10)
            .attr("ry", 10)
            .style("stroke", z(++i))
            .style("stroke-opacity", 1)
            .style("opacity", 0.7)
          .transition()
            .duration(5000)
            .ease(Math.sqrt)
            .attr("x", m[0] - 100)
            .attr("y", m[1] - 100)
            .attr("height", 200)
            .attr("width", 200)
            .style("stroke-opacity", 1e-6)
            .style("opacity", 1e-6)
            .remove();
    }
</script>

函数绘图(){
var w=600,
h=400,
z=d3.scale.category20b(),
i=0;
var svg=d3.select(“div.container2”).append(“svg:svg”)
.attr(“宽度”,w)
.attr(“高度”,h)
.on(“mousemove”,粒子);
}
函数粒子(){
var m=d3.鼠标(此);
append(“svg:rect”)
.attr(“x”,m[0]-10)
.attr(“y”,m[1]-10)
.attr(“高度”,20)
.attr(“宽度”,20)
.attr(“rx”,10)
.attr(“ry”,10)
.样式(“笔划”,z(++i))
.style(“笔划不透明度”,1)
.样式(“不透明度”,0.7)
.transition()
.持续时间(5000)
.ease(Math.sqrt)
.attr(“x”,m[0]-100)
.attr(“y”,m[1]-100)
.attr(“高度”,200)
.attr(“宽度”,200)
.样式(“笔划不透明度”,1e-6)
.样式(“不透明度”,1e-6)
.remove();
}

函数
draw()
particle()
调用您的需求。

谢谢您的回复。但是,我希望能够跨多个页面使用,并发布各种数据。作为一个可以重复使用的独立文件不是更好吗?非常感谢!!!!