iframe之父子窗口元素获取

iframe之父子窗口元素获取

iframe会涉及到事件绑定,样式更改的问题;但是由于元素在父窗口和子窗口不同的document中,无法跨doc获取。

在iframe中获取父窗口的元素

    $('#父窗口中的元素ID', parent.document).click();//指定$筛选元素的document

在父窗口中获取iframe中的元素 

    var test = $("#iframe的ID").contents().find("#iframe中的控件ID");//jquery 方法1 

  var test2 =  $("#iframe中的控件ID",document.frames("frame的name").document);//jquery 方法2
  var test3 = document.getElementById('iframe的id').contentWindow.document.getElementById('iframe里要获取的元素的id');//js方法

发表评论

您的电子邮箱地址不会被公开。

CAPTCHAis initialing...