-3

我有一个这样的脚本,它运行良好!

<div id="player"></div>

jQuery文件:

$(document).ready(function(){
    //You can alternatively pass an object:

    $('#player').youTubeEmbed({
        video       : 'http://www.youtube.com/watch?v=uyeJXKfAcpc',
        width       : 640,      // Height is calculated automatically
        progressBar : true      // Hide the progress bar
    });
});

但现在我想在这样的输入值中制作 youtube id:

<div id="player">
    <input type="hidden" name="youtube-id" value="uyeJXKfAcpc" />
</div>

并将其传递给 jquery 是这样的:

$(document).ready(function(){
    //You can alternatively pass an object:
    $('#player').youTubeEmbed({
        var yid = $(this).children("input[name='youtube-id']"),
        video       : 'http://www.youtube.com/watch?v=' . yid,
        width       : 640,      // Height is calculated automatically
        progressBar : true      // Hide the progress bar
    });
});
4

2 回答 2

3

You are declaring a variable inside an object, move it to above the youTubeEmbed plugin, also use the .val() method to access the input's value.

var yid = $("input[name='youtube-id']").val();
$('#player').youTubeEmbed({
    video           : 'http://www.youtube.com/watch?v=' + yid,
    width           : 640,      // Height is calculated automatically
    progressBar : true      // Hide the progress bar
});
于 2012-08-05T04:39:46.227 回答
0

根本不需要使用输入。做 -

<div id="player" data-youtube="uyeJXKfAcpc"></div>

你的 jQuery -

$('#player').youTubeEmbed({
    video: 'http://www.youtube.com/watch?v=' + $(this).attr('data-youtube'),
    width: 640,
    progressBar: true
});
于 2012-08-05T05:29:16.250 回答