2009-11-25 90 views
0

可能聽起來像一個總noob問題,但我正在尋找一個JavaScript(或和jQuery的)功能在此代碼替換元素:jQuery的替換字符串

<embed id="ply" width="800" height="400" 
flashvars="file=http://example.com/play/" 
allowscriptaccess="always" 
allowfullscreen="true" 
quality="high" bgcolor="#00000" 
name="ply" style="" 
src="/video-player.swf" 
type="application/x-shockwave-flash"/> 

我希望能夠更換:

flashvars="file=http://example.com/play/" 

並添加一些文字(視頻搜索):

flashvars="file=http://example.com/play/234983" 

一定很容易做到,但我感謝一些更有經驗的用戶的幫助。

+0

你知道改變屬性字符串不會自動重新加載視頻與你的新網址嗎? – 2009-11-25 19:12:34

+0

嗯,你是對的,我該如何強制玩家重新加載? – Disco 2009-11-25 19:20:16

+0

你可以修改它,因爲我在下面給出了一個例子,但刪除然後重新使用它。 – HackedByChinese 2009-11-25 19:21:20

回答

1
$("#ply").attr("flashvars", $("#ply").attr("flashvars") + "/234983"); 

更新 如果你想重新加載播放器,這可能工作。它將克隆ID爲ply的現有嵌入標籤,只替換flashvars屬性值。這有效地從DOM中刪除ply,然後再次將其插入到位。這有望使瀏覽器重新加載播放器。

var p = $("#ply"); 
p.replaceWith(p.clone().attr("flashvars", p.attr("flashvars") + "/234983")); 
+0

是的,就像一個魅力。謝謝 ! – Disco 2009-11-25 22:42:19