2012-01-26 9 views
0

ユーザーがソート可能なリストを使用して入力フィールドを使用してリンクを追加できるようにする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); 

答えて

1

はあなたが始めるために何かです。申し訳ありませんが、あなたのコードには何もないので、jQueryが必要なのか分かりませんでした。

+0

感謝を! –

0
new_element.addEventListener('click' vid_clicked); 

function vid_clicked(e){ 
    e=e?e:window.event; 
    var id=e.target.id; 
} 

おっと:ここ

0

あなたのリストはDOM内に存在します。関数に関数を渡す必要はなく、キューに追加するプロセス内でそれらを選択するだけで済みます。以下のような何かがトリックを行う必要があります。

var yourFunction = function() { 
    var items = $("#sortable>li"); 
    for (item in items) { 
     // put items[item] into your queue. 
    } 
} 

あなたの周りにそれらを通過したいならば、それからだけでセレクタを渡す。助けを

someFunction($("#sortable>li")); 
関連する問題