2009-09-24 120 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>