1

我有这个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>

在页面中,如果用户单击按钮,我需要根据用户单击的选项更改视频。(当用户 lick 我生成 时task2Video[username],请参见下面我声明的。)

我的视频库:

var task2Video = {
    jonkimpaulo : "Task_2.4a_Host_treated",
    jonpaulokim : "Task_2.4a_Host_treated",
    kimjonpaulo : "Task_2.5a_Host_treated",
    kimpaulojon : "Task_2.5a_Host_treated",
    paulokimjon : "Task_2.6a_Host_treated",
    paulojonkim : "Task_2.6a_Host_treated"
}

使用上面的名称,我如何替换所有 3 种格式?使用类似:

task2Video[task2Video]……这样吗?

4

1 回答 1

0

假设您想保留特定的文件扩展名,您的脚本可能如下所示:

// TODO implement yourself according to your needs
var nextvideo = task2Video.paulokimjon; 

// iterate thru all video sources
$('video source').each(function() {

    // remember the suffix
    var suffix = $(this).attr('src').split('.').pop();

    // update src (using new value, appending suffix)
    $(this).attr('src', nextvideo + '.' + suffix);

});

请参阅此演示

于 2012-10-22T09:10:34.667 回答