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

查看:42
本文介绍了通过单击链接更改 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天全站免登陆