"window.frames[0].variable" doesn't work in jquery $(function(){})?
In parent.html I set an iframe with child.html in it.
in child frame,I write js:
$(function () {
var child = 6;
})
开发者_Go百科
in parent frame,I write js:
$(function () {
alert(window.frames[0].child);
});
but the alert result is "undefined"?
How can I quote another frame's variable correctly with jquery?
You're seeing undefined because you're delcaring it as a local variable (scoped only to that document.ready handler), you would need this in the child frame for a global:
$(function () {
window.child = 6;
});
Also, there's no guarantee that a document.ready on the parent frame won't execute before the child frame (stick an alert() in each to see the order)...in fact it should be the opposite. If you're not using it immediately, it's not an issue...if you are you need to execute it later.
加载中,请稍侯......
精彩评论