JQuery脚本没有按预期工作

时间:2013-06-09 10:47:04

标签: jquery html jquery-plugins

我的HTML页面中有以下代码:

<html>
<head>
 <script type='text/javascript' src='http://code.jquery.com/jquery-1.7.1.js'></script>
 <script type='text/javascript' src="http://www.tikku.com/scripts/ui/tubeplayer/jQuery.tubeplayer.min.js"></script>
 <script type='text/javascript'>
jQuery("#player").tubeplayer({
    width: 600,
    // the width of the player
    height: 450,
    // the height of the player
    allowFullScreen: "true",
    // true by default, allow user to go full screen
    initialVideo: "rGdViHARBC0",
    // the video that is loaded into the player
    preferredQuality: "default",
    // preferred quality: default, small, medium, large, hd720
    onPlay: function(id) {},
    // after the play method is called
    autoPlay: true,
    onPause: function() {},
    // after the pause method is called
    onStop: function() {},
    // after the player is stopped
    onSeek: function(time) {},
    // after the video has been seeked to a defined point
    onMute: function() {},
    // after the player is muted
    onUnMute: function() {},
    // after the player is unmuted
    onPlayerEnded: function() {
        alert('ENDED')
    },
});
</script>
</head>
<body>
<div id="player"></div>
</body>
</html>

我从this JSFiddlePage那里得到了很多。尽管如此,我的页面变成了完全白色。我想使用Tubeplayer API查看youtube视频。为什么我的网站没有显示视频?

1 个答案:

答案 0 :(得分:3)

您必须等待DOM ready事件。你在里面编写代码:

$(function(){ //short hand for: $(document).ready()
    jQuery("#player").tubeplayer({...});
});

或者在正文结束标记之前放置脚本标记。