ユーザーがソート可能なリストを使用して入力フィールドを使用してリンクを追加できるようにするYouTube Webアプリケーションを開発中です。 urlがURL構造をチェックするための一致関数を渡すと、ビデオIDが取得され、それ自身のインデックスの下に配列に配置されます。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をキュー機能に渡す新しいli要素にリンクを追加することです。これを達成し始めるにはどうしたらいいですか?
var refId = _videoList.length;
var $new_element = $('li').attr('id', refId);
var $link = $('a')
.attr('href', _videoUrl)
.innerHtml(_videoUrl)
.data('refId', refId) // add parent li's id for reference in click event
.appendTo($new_element)
.bind('click', function(){
cue($link.data('refId'));
return false; // prevent browser's default click event
});
$new_element.appendTo(container);
感謝を! –