我正在研究一個YouTube Web應用程序,該應用程序允許用戶使用可排序列表使用輸入字段添加鏈接。一旦url傳遞一個匹配函數來檢查url結構,視頻ID就被抓取並放置在它自己的索引下的Array中。JQuery將列表變量傳遞給另一個函數
var _videoList = new Array();
if (matchesReg)
{
var container = document.getElementById('sortable');
var _videoId;
//grab the video ID from the URL
_videoId = _videoUrl.replace(/^[^v]+v.(.{11}).*/,"$1");
//place the Videoid in an array
_videoList[_videoList.length] = _videoId;
var new_element = document.createElement('li');
//set the id of the li element to match it's position in the array
new_element.id = _videoList.length;
new_element.innerHTML = _videoUrl;
container.insertBefore(new_element, container.firstChild);
//diplay the vaild link message
document.getElementById('msg').style.display="block";
document.getElementById('msg').innerHTML = "Video URL added!";
// Clean input field
document.getElementById('newVideo').value="";
} else {
//failed to pass the regex test, diplay error
document.getElementById('msg').style.display="block";
document.getElementById('msg').innerHTML = "Error! Not a valid YouTube URL.";
}
我想要做什麼它添加一個鏈接到每個新的鋰元素,將視頻ID傳遞給一個提示函數。我怎麼可能開始實現這個目標?
感謝您的幫助! –