如何使用 Jquery 在 iframe 中加载 url [英] How do I load an url in iframe with Jquery

查看:86
本文介绍了如何使用 Jquery 在 iframe 中加载 url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在点击时加载一个 iframe,这是我目前所拥有的:

$("#frame").click(function () {$('this').load("http://www.google.com/");});

它不起作用.这是完整的代码:JS Bin

解决方案

$("#button").click(function () {$("#frame").attr("src", "http://www.example.com/");});

HTML:

 

<iframe id="frame" src="" width="100%" height="300"></iframe>

<button id="button">加载</button>

I want to load an iframe on click, this is what I have so far:

$("#frame").click(function () { 
      $('this').load("http://www.google.com/");
    });

It doesn't work. This is the complete code: JS Bin

解决方案

$("#button").click(function () { 
    $("#frame").attr("src", "http://www.example.com/");
});

HTML:

 <div id="mydiv">
     <iframe id="frame" src="" width="100%" height="300">
     </iframe>
 </div>
 <button id="button">Load</button>

这篇关于如何使用 Jquery 在 iframe 中加载 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆