2009-09-24 124 views
10

更改IFRAME SRC我有一个iframe,看起来像这样:通过单击链接

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

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

回答

50

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

给你的iframe中name,并定位您的锚指向它:

<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的人。

0

上点击链接“点击这里” //将采取的链接移动到所指定的iframe ....

<a href="cart.html" target="test" onclick="document.getElementById('test').frameBorder=1"> Click Here </a> 
<iframe src="blank.html" frameborder="0" name="test" id="test" width=1200 height=800></iframe>