
补充:
jQuery中each类似于javascript的for循环
但不同于for循环的是在each里面不能使用break结束循环,也不能使用continue来结束本次循环,想要实现类似的功能就只能用return,
break 用return false
continue 用return ture
下面简单使用jQuery来操作iframe的一些记录
第一、在iframe中查找父页面元素的方法:
$('#id', window.parent.document)
第二、在父页面中获取iframe中的元素方法:
$(this).contents().find("#suggestBox")
第三、在iframe中调用父页面中定义的方法和变量:
parent.method
parent.value
iframe里用jquery获取父页面body
iframe.html
<html> <script src='jquerymin.js'> </script> <body id='1'> <div>it is a iframe</div> </body> <script> $(document).ready( function() { var c = $(window.parent.document.body) //麻烦的方法: var c = $($(window).eq(0)[0].parent.document).find('body'); ,忘了可以用前面的方法了 alert(c.html()); } ); </script> </html>
content.html <html> <script src='jquerymin.js'> </script> <body id='fa'> <iframe src='iframe.html' width='100' height='100'></iframe> <br> <br> <br> <div id='mydiv'>content iframe</div> </body> <script> function a() { alert(1); } alert($(document).text()); </script> </html>
实际项目中应用的代码
function myCheck(iframe){ var flag = true; $("input[name]",iframe.document).each(function(){ if($(this).attr("name")=="contentImage") return true; if($(this).val()==""){ alert("表单不允许有空选项,请填写完整"); $(this).focus(); flag= false; return flag; } }); return flag; }
- 上一篇 关于ajax无历史记录问题的解决
- 下一篇 拓展js中String对象的方法