我正在尝试根据用户的选择更改vlc视频的目标/来源。这就是我到目前为止所做的:
$('select').change(function() {
var router = $(this).val();
alert("The port number is "+router);
var link = "http://xxx:"+router+"/videostream.cgi?user=admin&pwd=cam1&t=";
alert("The stored link is: "+link);
alert("The current target is: "+$("#vlc").attr("target"));
$("#vlc").attr("target",link);
alert("The new target is: "+$("#vlc").attr("target",link));
});
选择:
<select name="cameras" id="cameras">
<option value="1101">Cam 1</option>
<option value="1102">Cam 2</option>
</select>
vlc对象:
<embed type="application/x-vlc-plugin" pluginspage="http://www.videolan.org" version="VideoLAN.VLCPlugin.2" width="500" height="500" id="vlc" loop="yes" autoplay="yes" target="http://xxx:1101/videostream.cgi?user=admin&pwd=cam1&t="></embed>
xxx是指用户的IP。警报是出于我自己的测试目的。前三个应该关闭,但最后一个返回[object Object]。我已经能够改变vlc对象的其他属性,比如宽度,所以它是我缺少的目标属性
答案 0 :(得分:1)
在更改<embed>
属性之前,必须从DOM中分离target
元素。然后再次附上它。
var embed, embedParent;
$('select').change(function() {
var router = $(this).val();
alert("The port number is "+router);
var link = "http://xxx:"+router+"/videostream.cgi?user=admin&pwd=cam1&t=";
alert("The stored link is: "+link);
alert("The current target is: "+$("#vlc").attr("target"));
// getting parent for further use
embedParent = $("#vlc").parent();
// will remove element from DOM and assing to embed var
embed = $("#vlc").detach();
embed.attr("target", link);
embed.appendTo(embedParent);
});