开发者

Show values in another document controls

I want to show some JavaScript array values in another document Input Boxes. Previously, I was using:

document.getElementByID('....').value = ....

Now I want to know how to replace the 'document' with another page.

Edited:

My page opens two tables side-by-side. First table contains controls and the second contains and IFrame and inside that frame is enclosed a data-grid. When the user clicks on a row in the开发者_Go百科 grid, results are fetched and I want to show in the controls of table1.


You can use the context of the jQuery method ie the $(..., context) to do this.

$("#someElement", top.document).val($("#someOtherElement").val());

This sets the value of #someElement in the main document, to the value of #someOtherElement in the iframe. Code is supposed to be run from within the iframe, because that's where your button handling is most likely to be.

To go the other way you could use:

$("#someElement", $("#iframeId").contents()).val($("#someOtherElement").val());


In JavaScript the only other documents you can reference are iframes inside the page itself that have the same domain. You could simply do, var iframeDocument = document.getElementById("iframeId").contentWindow.document

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜