網(wǎng)上看了別人的獲取值的例子,我又加上了修改iframe里元素值的部分供大家參考 主頁(yè)面:1.html <html> <head> <title>jquery方式,訪問iframe頁(yè)面dom元素</title> <meta name="Author" content="孫勤波"> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> <script type="text/javascript" src="http://s1./r/www/cache/static/jquery/jquery-1.10.2.min_f2fb5194.js"></script> </head> <body> <iframe src="2.html" id="frame_1"></iframe> <br /> <a id="set_target" href="javascript:getIframeDom();">獲取iframe 頁(yè)面test元素內(nèi)容</a> <a id="stest" href="aaaa">bbb</a> <script type="text/javascript"> function getIframeDom(){ // 獲取iframe的test元素 var test = $("#frame_1").contents().find("#test"); alert(test.html()); var lurl= $("#frame_1").contents().find("#url_location"); alert(lurl.html()); lurl.attr("target","_blank"); } var $iFrame=$("#frame_1"); $iFrame.prop("src","http://ny./temp/2.html"); $iFrame.load(function(){ //alert("加載完畢"); var test = $("#frame_1").contents().find("#test"); alert(test.html()); var lurl= $("#frame_1").contents().find("#url_location"); alert(lurl.html()); lurl.attr("target","_blank"); }); </script> </body> </html> Iframe頁(yè)面:2.html <html> <head> <title>iframe頁(yè)面a.html</title> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> </head> <body> <div id="test">我是測(cè)試頁(yè)面test</div> <a id="url_location" href="3.html">open the new window</a> </body> </html> |
|