更新时间:2023-01-08 15:54:53
使用jQuery,您可以按需加载和执行JavaScript 。在加载脚本之前,请将播放列表部分附加到脚本网址,如下所示:
With jQuery you can load and execute JavaScript on demand. Before loading the script, append the playlist part to the script url like this:
HTML
<a href="playlisturl" class="playlist-link">Play list A</a>
<a href="playlisturl" class="playlist-link">Play list B</a>
<a href="playlisturl" class="playlist-link">Play list C</a>
jQuery
$(".playlist-link").click(function(e){
e.preventDefault();
var playlist = $(this).attr("href");
var url = 'http://www.viddler.com/tools/vidget.js' +
'?widget_type=js_list' +
'&widget_width=940' +
'&source=playlist' +
'&user=USERNAME ' +
'&playlist='+ playlist +
'&style=grid'+
'&show_player=true'+
'&player_type=simple'+
'&max=12'+
'&videos_per_row=6'+
'&v=2.0'+
'&id=XXXXXXXXXX';
$.getScript(url, function(data, textStatus){
alert('This is executed after your script is loaded');
});
});