通过单击链接更改iframe src [英] Change iframe src by clicking a link

查看:96
本文介绍了通过单击链接更改iframe src的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 iframe ,看起来像这样:

I have an iframe that looks like this:

<iframe src="http://www.google.com" height=1000 width="500" id="myiframe"></iframe>

我想创建一个链接,当我点击它时,页面上的iframe会发生变化。我怎样才能使用jQuery?它与jQuery attr 有关吗?

I want to create a link so that when I click on it, the iframe on the page changes. How can I do that using jQuery? Is it related to jQuery attr?

推荐答案

您不需要jQuery。你甚至不需要JavaScript。

You don't need jQuery for that. You don't even need JavaScript for that.

给你的iframe一个 name ,然后把你的锚定到点到它:

Give your iframe a name, and target your anchors to point to it:

<a href="foo.html" target="myiframe">Foo</a>
<a href="bar.html" target="myiframe">Bar</a>
<a href="baz.html" target="myiframe">Baz</a>

<iframe name="myiframe"></iframe>

对于JavaScript关闭的人来说,这很好。

This degrades nicely for people who have JavaScript turned off.

这篇关于通过单击链接更改iframe src的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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