jquery取得父页面元素
-
有时候要去修改或取得父页面的元素,直接用id是取不到的,
方法哪下:
取父窗口的元素方法:$(selector, window.parent.document);
取父窗口的父窗口的元素就可以用:$(selector,window.parent.parent.document);
类似的,取其它窗口的方法大同小异
$(selector, window.top.document);
$(selector, window.opener.document);
$(selector, window.top.frames[0].document);
用什么根据0实际情况了,frame或iframe是window.top.document. 包含的子页面,或弹出的子页面,则用window.parent.document。
selector则可根据实际确定了,一般id最好,
例:$('#useremCount_MyMessage', window.top.document);