js积累:模拟onclick触发,添加节点,iframe对象

点滴知识来源于网络,当你提出问题的时候,答案已经出现

? ? //js 触发click

? ? //document.getElementById("LoadLayersTool").onclick();

? ? //添加元素到div下面

? ? //var div= document.getElementById("3DT1").contentWindow.document.getElementById("LoadLayersTool"); var div2 = document.createElement("button");?

? ? //div2.innerText = "test"; div2.setAttribute('style', 'color:red;left:100px');

? ? //div2.setAttribute('onclick', 'test()'); div.appendChild(div2); function test() { alert("1234"); }

? ? //获取iframe里面的对象

? ? //var iframe = document.getElementById("xxx");//父窗口获取iframe子窗口对象

? ? //var iframew = iframe.contentWindow;//iframe窗口的window对象

? ? //var iframed = iframew.document;//iframe窗口的document对象

? ? //var iframed2 = iframe.contentDocument;//DOM2也支持直接获取document对象