jquery正确获取iframe里元素的方法

 1 <iframe id="_ae_frame" width="100%" height="100%" frameborder="0" scrolling="auto" src="/videofile/preview?filename=bbb.mp4">
 2     <html>
 3         <head><meta name="viewport" content="width=device-width"></head>
 4         <body>
 5             <video controls="" autoplay="" name="media">
 6                 <source src="http://localhost:9980/videofile/preview?filename=bbb.mp4" type="video/mp4">
 7             </video>
 8         </body>
 9     </html>
10 
11 </iframe>

如上图,如果想获取video元素

正确方式:

$("#_ae_frame").contents().find("video[name='media']").html();

错误方式:

$("video").html();

猜你喜欢

转载自www.cnblogs.com/xuhongtaoloveqiandran/p/10899544.html
今日推荐