在我的例子中,如何将 Paper.set() 传递给另一个 Javascript?
我有一个index.html页面,其中包含一个按钮id="my-btn"
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>My INDEX PAGE</title>
</head>
<body>
<div id="my-canvas"></div>
<br><input type="button" id="my-btn" value="OPEN NEW WINDOW"/>
<script src="js/jquery-1.5.1.js"></script>
<script src="js/raphael.js"></script>
<script src="js/my-graph.js"></script>
<script src="js/my.js"></script>
</body>
</html>
js/my.js调用createCircle来自my-graph.js的
函数,并处理按钮点击事件,当点击my-btn
按钮时,一个新的浏览器将弹出一个新页面的窗口(test.html)
my.js:
MyTest.createCircle();
$('#my-btn').click(function(){
window.open('test.html', 'testwindow');
});
my-graph.js:
MyTest= function(){
var paper = Raphael("my-canvas", 320, 200);
var st=paper.set();
return {
createCircle: function(){
st.push(
paper.circle(10, 10, 5),
paper.circle(30, 10, 5)
);
}
getSet: function(){
return st;
}
};
}();
新页面(test.html< /strong>)在新的浏览器窗口中打开:
test.html:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>TEST</title>
</head>
<body>
<div id="my-name"></div>
<script src="js/jquery-1.5.1.js"></script>
<script src="js/my-graph.js"></script>
<script src="js/test.js"></script>
</body>
</html>
在新页面中,test.js将被调用我想传递 Paper.set() st
从 my-graph.js 到这个 test.js 并输出 st.length
作为此页面 js/test 的内容
。 js
$(document).ready(function(){
var st=MyTest.getSet();
$("#my-name").append("<strong>"+st.length+"</strong>");
});
但我总是在新弹出的页面中得到 0 长度的 st 。为什么?
I have a index.html page, which contains a buttonid="my-btn"
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>My INDEX PAGE</title>
</head>
<body>
<div id="my-canvas"></div>
<br><input type="button" id="my-btn" value="OPEN NEW WINDOW"/>
<script src="js/jquery-1.5.1.js"></script>
<script src="js/raphael.js"></script>
<script src="js/my-graph.js"></script>
<script src="js/my.js"></script>
</body>
</html>
js/my.js invoke createCircle
function from my-graph.js, and handles button click event, when my-btn
button is clicked, a new browser window will be popped up with a new page (test.html)
my.js:
MyTest.createCircle();
$('#my-btn').click(function(){
window.open('test.html', 'testwindow');
});
my-graph.js:
MyTest= function(){
var paper = Raphael("my-canvas", 320, 200);
var st=paper.set();
return {
createCircle: function(){
st.push(
paper.circle(10, 10, 5),
paper.circle(30, 10, 5)
);
}
getSet: function(){
return st;
}
};
}();
The new page(test.html) opened in new browser window:
test.html:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>TEST</title>
</head>
<body>
<div id="my-name"></div>
<script src="js/jquery-1.5.1.js"></script>
<script src="js/my-graph.js"></script>
<script src="js/test.js"></script>
</body>
</html>
In the new page, test.js will be invoked and I want to pass the Paper.set() st
from my-graph.js to this test.js and output st.length
as the content of this page
js/test.js
$(document).ready(function(){
var st=MyTest.getSet();
$("#my-name").append("<strong>"+st.length+"</strong>");
});
But I always get 0 length of the st in new popped up page. Why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所以您打开一个新页面,其中脚本引用相同的代码
正如另一页那样,
这并不意味着它们具有相同的状态。
新页面将从评估中获得自己的状态
脚本本身
你可以做的就是保存返回的引用,
你可以使用它来调用新页面上的函数
,或者你可以使用 jquery 完成起始页面上的所有代码
并使用该窗口对象作为上下文
拉斐尔对象设置为纸张,我认为不确定会发生什么
在论文之间传递它们时发生的事情:S
so your opening a new page with script references to the same code
as the other page
That dosent mean that they have the same state.
The new page will get its own state from evaluating
the script itself
what you can do is save the reference that
returns you can use that for calling a function on your new page
or you can yost do all the code on the start page with jquery
and useing that window object as your context
raphael objects are set to a paper i think not shure what will
happend when passing them betwen papers :S