可能听起来像一个总noob问题,但我正在寻找一个javascript(和或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 :(得分:1)
$("#ply").attr("flashvars", $("#ply").attr("flashvars") + "/234983");
<强>更新强>
如果你想重新加载播放器,这可能会有效。它将使用ID ply
克隆现有的embed标记,仅替换flashvars
属性值。这有效地从DOM中删除ply
,然后再次将其插入到位。这有望使浏览器重新加载播放器。
var p = $("#ply");
p.replaceWith(p.clone().attr("flashvars", p.attr("flashvars") + "/234983"));