Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/455.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Soundcloud API Javascript错误:$未定义_Javascript_Soundcloud - Fatal编程技术网

Soundcloud API Javascript错误:$未定义

Soundcloud API Javascript错误:$未定义,javascript,soundcloud,Javascript,Soundcloud,我是一名javascript初学者,当我尝试使用soundcloudAPI时,我遇到了这个错误: ReferenceError: $ is not defined $("#stream").live("click", function(){ 我删除了客户端ID和跟踪ID,但以下是我的脚本: <script type="text/javascript" src="http://connect.soundcloud.com/sdk.js"></script> <

我是一名javascript初学者,当我尝试使用
soundcloud
API时,我遇到了这个错误:

 ReferenceError: $ is not defined
 $("#stream").live("click", function(){
我删除了客户端ID和跟踪ID,但以下是我的脚本:

 <script type="text/javascript" src="http://connect.soundcloud.com/sdk.js"></script>
<script type="text/javascript">

    SC.initialize({
        client_id: "000000000000000000"
    });  

    $("#stream").live("click", function(){
        SC.stream("/tracks/000000000", {autoPlay: true});
    });

 </script>

SC.initialize({
客户端id:“000000000000000000000000”
});  
$(“#流”).live(“单击”,函数(){
SC.stream(“/tracks/000000000”,{autoPlay:true});
});
以及HTML:

 <head> 
    <meta charset="utf-8">
    <link rel="stylesheet" type="text/css" href="css/player.css" />
</head>

<body>
    <div id="container">
        <h1>earth. home. destroyed.</h1>
            <nav>
                <ul>
                    <li id="stream">► saturn boy</li>
                    <li>► gold</li>
                    <li>► earth</li>
                    <li>► from the sun</li>
                    <li>► cosmic landscapes</li>
                </ul>
            </nav>
    </div>

 </body>

地球。家。摧毁。
  • ► 土星男孩
  • ► 黄金
  • ► 土
  • ► 来自太阳
  • ► 宇宙景观
任何帮助都将不胜感激:)


谢谢

从脚本示例来看,您似乎缺少对jQuery的引用(它不是默认库-您必须在需要它的页面上使用它的任何脚本之前显式地包含它)

添加此项(在其他脚本标记之前)应该可以解决此问题:

<script type='text/javascript' src='http://code.jquery.com/jquery-latest.min.js'></script>
  • 这将仅在点击
    #stream
    元素时触发处理程序-但是
    #stream
    元素不需要首先在页面上-只有容器
    ul
    才需要。如果您也在动态创建
    ul
    ,您可以“向上”一级并将选择器更改为此
    #container>h1>nav
    (这具有类似的效果,但此处也可以动态添加
    ul
更多关于带有“on”的活动委派的信息:


…希望这有帮助

$(“#流”).live(“单击”,函数(){…});是jQuery,你包括jQuery库了吗?哦,我还以为它只是SounClud API的Javascript。非常感谢。Firebug中不再存在JavaScript错误,但它不起作用。可能是我的track_id出错或类似的问题。我会继续努力,谢谢:)
$('#container > h1 > nav > ul').on('click', '#stream', function(){
    SC.stream("/tracks/000000000", {autoPlay: true});
});