jQuery-如何获取视频src值? [英] Jquery - how i can get the video src value?
本文介绍了jQuery-如何获取视频src值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要获取视频的价值,并需要更改为新的价值...为此,我使用了此功能:
i need to get the value of a video and need to change in to new value... for that i used this function:
var video = $('#task2ResultVideo').get(0);
console.log($(video).attr('poster')); // i am getting this
$(video).attr('src',function(num,val){
console.log(num,val) // i am not getting this..
})
HTML:
<video id="task2ResultVideo" autobuffer poster="img/task2-results-host-poster.jpg">
<source src="Video/webm/Task_2.4a_Host_treated.webm" type="video/webm" />
<source src="Video/ogv/Task_2.4a_Host_treated.theora.ogv" type="video/ogg" />
<source src="Video/MP4/Task_2.4a_Host_treated.mp4" type="video/mp4" />
</video>
但是我无法获得这些值.我的代码有什么问题?如果我获得该值,该如何更改src?
But i am not able to get the values. what is wrong with my code? in case if i get the value how can i change the src?
有什么建议吗?
推荐答案
尝试一下,
Live Demo
$('video source').each(function(num,val){
console.log($(this).attr('src')); // i am not getting this..
$(this).attr('src', 'newSourceValue')
});
根据OP的评论,更改src文件名
Based on the comments by OP, changing the src filename
Live Demo
$('video source').each(function(num,val){
console.log($(this).attr('src')); // i am not getting this..
strSrc = $(this).attr('src');
strPath = strSrc.substring(0, strSrc.lastIndexOf('/'));
strExtenion = strSrc.substring(strSrc.lastIndexOf('.'));
$(this).attr('src', strPath + "/" + "newFileName" + strExtenion );
});
这篇关于jQuery-如何获取视频src值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文