簡體   English   中英

我們可以使用javascript設置目標或src等HTML5標簽的屬性嗎?

[英]Can we set attributes of HTML5 tags like target or src using javascript?

我是這個論壇的新手。 我在將“目標”屬性傳遞到嵌入vlc TAG時遇到了一個小問題。 請查看以下代碼,並幫幫我..

我試圖更改“寬度”屬性,但更改成功。 我不明白為什么“目標”僅存在問題。 但是,只要我們直接將目標直接添加到embed標簽中,它就可以工作。

請幫幫我。

我的目標是能夠傳遞不同的文件路徑,以便查看我想要的視頻。 我嘗試使用視頻標記並更改其src屬性,但是那也不起作用。 這是代碼

<html>
<head>
<script language="javascript">

window.onload = function() 
{
document.getElementById("player").width = "800";
//document.getElementById("player").target = "sample.mp4";
document.getElementById("player").setAttribute("target","sample.mp4"); // only this attribute is not being passed
alert(document.getElementById("player").getAttribute("target")); // I am also getting the alert as 'sample.mp4'
}
</script>
</head>

<body>
<embed type="application/x-vlc-plugin" id="player" name="VLC" autoplay="yes" loop="no" volume="100" width="640" height="480" />
</body>
</html>

我遇到了類似的問題,最終我決定使用VLC播放列表對象,而不是設置target屬性。

var vlc = document.getElementById("player");
vlc.playlist.items.clear();
var id = vlc.playlist.add(src);
vlc.playlist.playItem(id);

有關VLC播放列表的完整文檔,請參見此處

根據w3schools.com,HTML5 embed元素沒有“目標”屬性: http : //www.w3schools.com/html5/tag_embed.asp )。

但是,VLC插件顯然會讀取它: http ://wiki.videolan.org/Documentation:WebPlugin#Embed_tag_attributes

我覺得這很奇怪。 如果w3schools是正確的,目標屬性將無法驗證?

在我看來,您想要更改指定播放視頻的屬性,以便對其進行更改,是嗎? 我不能說我是專家,因為我沒有像這樣直接處理VLC插件,但是我想知道這是否有幫助: http : //forum.videolan.org/viewtopic.php?f=16&t = 57845

另外,從http://wiki.videolan.org/Documentation:WebPlugin#Playlist_object看來,在VLC-本機方式。

為什么不使用jQuery? 然后就這么簡單:

$('#player').attr('target', 'sample.mp4');

檢索屬性值很容易:

$('#player').attr('target');

要進一步閱讀,請使用jQuery文檔:

http://docs.jquery.com/Main_Page

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM