Javascript 我无法将单击的值传递到函数中
: 嗨, 我无法将单击的值传递给返回函数Javascript 我无法将单击的值传递到函数中,javascript,jquery,youtube-api,Javascript,Jquery,Youtube Api,: 嗨, 我无法将单击的值传递给返回函数 function getArtistId() { //return 'l-gQLqv9f4o'; if i uncomment this videos will work like charm, but instead of static i need dynamic onclick of the element getting the value and passing. return 'ytData1';
function getArtistId() {
//return 'l-gQLqv9f4o'; if i uncomment this videos will work like charm, but instead of static i need dynamic onclick of the element getting the value and passing.
return 'ytData1';
}
JS:
因为我无法将单击的值传递给返回函数
function getArtistId() {
//return 'l-gQLqv9f4o'; if i uncomment this videos will work like charm, but instead of static i need dynamic onclick of the element getting the value and passing.
return 'ytData1';
}
在这段代码中很难找到问题,请帮助我……一个简单的解决方案是使用全局变量,方法是使用
窗口。变量
$('.new li #c-vid').on('click', function(e) {
$(this).each(function(i, obj) {
e.preventDefault();
cVid = document.getElementById('c-vid');
window.artist_id = $(this).attr('data-yt');
loadPlayer();
})
});
然后只需更新您的getArtistId
函数
function getArtistId() {
return window.artist_id;
}
不客气。你介意选择我的答案作为你问题的正确答案吗?Thxy你给了我一票,但没有选择它作为正确答案,如果你在投票下勾选,有一个小的绿色标记,你可以按下,这将标记我的答案为正确答案。谢谢