从链接href更改iframe来源 [英] Change iframe source from link href
本文介绍了从链接href更改iframe来源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要从<a>
网址更改iframe源. http://jsfiddle.net/YkKu3/
I need to change iframe source from <a>
url. http://jsfiddle.net/YkKu3/
我的HTML:
<a class='gotothis' href='http://puu.sh/666.png'>this Image</a>
<button type="button">Click Me!</button>
<iframe id="frameimg" src="" width="300" height="300">
</iframe>
$('button').click( function(event) {
var clicked = $(this);
$("#frameimg").attr("src", " .gotothis image is here, help '); // Here the problem
});
推荐答案
您混合了事件的顺序.正确的代码会将锚点网址加载到iframe中:
You have the order of events mixed up. Correct code that will load the anchor URL into the iframe:
$(window).load(function() {
$('button').click( function(event) {
var clicked = $(this);
window.setTimeout(function() {
$("#frameimg").attr("src", $(".gotothis").attr("href"));
}, 1000);
});
});
在线测试用例. (和一只可爱的猫:))
Live test case. (With a cute cat :))
这篇关于从链接href更改iframe来源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文