简体   繁体   English

我们可以使用javascript设置目标或src等HTML5标签的属性吗?

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

I am new to this forum. 我是这个论坛的新手。 I am facing a small problem in passing "target" attribute into embed vlc TAG. 我在将“目标”属性传递到嵌入vlc TAG时遇到了一个小问题。 Please look into the below code and help me out.. 请查看以下代码,并帮帮我..

I tried to change the "width" attribute and it is being change successfully. 我试图更改“宽度”属性,但更改成功。 I don't understand why there is a problem with "target" only. 我不明白为什么“目标”仅存在问题。 But it works if we just add the target directly in the embed tag. 但是,只要我们直接将目标直接添加到embed标签中,它就可以工作。

Please help me out. 请帮帮我。

My aim is to be able to pass different file paths so as to view the video I wanted. 我的目标是能够传递不同的文件路径,以便查看我想要的视频。 I tried using video tag and change its src attribute but that,s not working too. 我尝试使用视频标记并更改其src属性,但是那也不起作用。 Here is the code 这是代码

<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>

I had a similar issue and in the end i decided to use the VLC playlist object instead of setting the target attribute. 我遇到了类似的问题,最终我决定使用VLC播放列表对象,而不是设置target属性。

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

The full documentation for the VLC playlist can be found here . 有关VLC播放列表的完整文档,请参见此处

The HTML5 embed element doesn't have a "target" attribute according to w3schools.com: http://www.w3schools.com/html5/tag_embed.asp ). 根据w3schools.com,HTML5 embed元素没有“目标”属性: http : //www.w3schools.com/html5/tag_embed.asp )。

However, the VLC plugin apparently reads it: http://wiki.videolan.org/Documentation:WebPlugin#Embed_tag_attributes 但是,VLC插件显然会读取它: http ://wiki.videolan.org/Documentation:WebPlugin#Embed_tag_attributes

That seems strange to me; 我觉得这很奇怪。 if w3schools is correct, the target attribute would fail to validate? 如果w3schools是正确的,目标属性将无法验证?

It sounds to me like you're wanting to change the attribute which specifies the playing video, in order to change it, yes? 在我看来,您想要更改指定播放视频的属性,以便对其进行更改,是吗? I can't say I'm an expert, as I've not dealt directly with teh VLC plugin like this, but I wonder if this might help: http://forum.videolan.org/viewtopic.php?f=16&t=57845 我不能说我是专家,因为我没有像这样直接处理VLC插件,但是我想知道这是否有帮助: http : //forum.videolan.org/viewtopic.php?f=16&t = 57845

Also, from http://wiki.videolan.org/Documentation:WebPlugin#Playlist_object , it seems that accessing the plugin's playlist object, adding a new item, and then immediately using next() could achieve what you want, in a VLC-native way. 另外,从http://wiki.videolan.org/Documentation:WebPlugin#Playlist_object看来,在VLC-本机方式。

Why not use jQuery? 为什么不使用jQuery? then it's as easy as: 然后就这么简单:

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

Retreiving attribute values is as easy as: 检索属性值很容易:

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

for further reading, use the jQuery documentation: 要进一步阅读,请使用jQuery文档:

http://docs.jquery.com/Main_Page http://docs.jquery.com/Main_Page

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有没有办法使用HTML5,Javascript或PHP设置视频时长的限制? 有点像手套和藤蔓 - Is there a way I can set a limitation of the videos duration using HTML5, Javascript or PHP? Sort of like snapchat and vine 我们可以使用phonegap访问HTML5和javascript中的Android设备的联系人列表,相机图片等原生内容吗? - Can we access native things like contact list, camera pictures, etc of an android device in HTML5 and javascript using phonegap? 使用Javascript动态替换HTML5标签 - Dynamically replace HTML5 tags using Javascript JavaScript动态将img src设置为HTML5上传的文件 - JavaScript dynamically set img src to HTML5 uploaded file 如何使用 Javascript 在字符串中找到类似 HTML 的标签? - How can I find HTML like tags in a string using Javascript? 可以使用jQuery添加html5&#39;a&#39;属性吗 - Can html5 'a' attributes be added using jQuery 使用Jetbrains Webstorm更改HTML5和Javascript中图像的src - Changing the src of an Image in HTML5 and Javascript using Jetbrains Webstorm 如何使用单选按钮使用HTML5和Javascript更改img src - How to change img src with HTML5 and Javascript using radio button JavaScript-HTML5数据属性 - JavaScript - HTML5 data attributes 测试 HTML5 标签、事件和属性支持 - Tests for HTML5 tags, events, and attributes support
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM