iFrame jQuery在父级中调用jQuery函数 如何让iFrame中的jQuery调用父级中的jQuery函数
以下是iFrame的代码iFrame jQuery在父级中调用jQuery函数 如何让iFrame中的jQuery调用父级中的jQuery函数,jquery,function,iframe,Jquery,Function,Iframe,以下是iFrame的代码 <script> $(document).ready(function (){ $("#Hey").click(function () { parent.WorkPlease(); // does not work window.parent.WorkPlease(); // also does not work /
<script>
$(document).ready(function (){
$("#Hey").click(function ()
{
parent.WorkPlease(); // does not work
window.parent.WorkPlease(); // also does not work
// Both hosted on same domain
});
});
</script>
<script type="text/javascript">
$(document).ready(function(){
function WorkPlease()
{
$('html,body').animate({scrollTop: $("#iFrame").offset().top}, 5000);//
}
});
</script>
$(文档).ready(函数(){
$(“#嘿”)。单击(函数()
{
parent.WorkPlease();//不起作用
window.parent.WorkPlease();//也不起作用
//两者都托管在同一个域上
});
});
这是承载iFrame的父页面上的jQuery
<script>
$(document).ready(function (){
$("#Hey").click(function ()
{
parent.WorkPlease(); // does not work
window.parent.WorkPlease(); // also does not work
// Both hosted on same domain
});
});
</script>
<script type="text/javascript">
$(document).ready(function(){
function WorkPlease()
{
$('html,body').animate({scrollTop: $("#iFrame").offset().top}, 5000);//
}
});
</script>
$(文档).ready(函数(){
函数WorkPlease()
{
$('html,body').animate({scrollTop:$(“#iFrame”).offset().top},5000);//
}
});
您可以从iframe
访问父级的DOM,但要在同一个域中。这似乎是你的情况
代码的问题在于,workPlease
函数被定义为传递给文档
窗口
对象
尝试:
您可以从
iframe
访问父级的DOM,但要在同一个域中。这似乎是你的情况
代码的问题在于,workPlease
函数被定义为传递给文档
窗口
对象
尝试:
我可以通过iFrame中的jQuery控制父级中的另一个div。这不是访问外部内容吗$(document).ready(function(){$(“#嘿”)。单击(function(){/$(this).animate(function(){window.parent.$(“.Main”).animate({height:“300px”},1500);//});});你是对的。您应该能够从同一域中访问父窗口对象。我查看了你的代码,发现问题出在其他地方。就是这样!你明白了,兄弟。谢谢我的朋友。我可以在iFrame中从jQuery控制父对象中的另一个div。这不是访问外部内容吗$(document).ready(function(){$(“#嘿”)。单击(function(){/$(this).animate(function(){window.parent.$(“.Main”).animate({height:“300px”},1500);//});});你是对的。您应该能够从同一域中访问父窗口对象。我查看了你的代码,发现问题出在其他地方。就是这样!你明白了,兄弟。谢谢我的朋友。