Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.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
JQuery单击代码未执行_Jquery_Html_Node.js - Fatal编程技术网

JQuery单击代码未执行

JQuery单击代码未执行,jquery,html,node.js,Jquery,Html,Node.js,当我点击“播放”按钮时,一定会显示“用户点击了”foo“的警报,但这并没有发生。ie未调用jquery单击处理程序 <html> <head> <script type = "text/javascript" src ="new.js"></script> <script src = "/socket.io/socket.io.js"></script>

当我点击“播放”按钮时,一定会显示“用户点击了”foo“的警报,但这并没有发生。ie未调用jquery单击处理程序

<html>
        <head>
          <script type = "text/javascript" src ="new.js"></script>
          <script src = "/socket.io/socket.io.js"></script>
          <script src="jquery-3.1.1.min.js"></script>
        </head>
        <body>
            <button type="button" id = "play" name = "play" value = "play">PLAY</button>
            <button onclick = "pauseAd()" type ="button" name = "pause" value = "pause">PAUSE</button>
            </br>
            <audio controls id = "song">
                <source src = "Lyrics to Swallowed in the Sea - Coldplay.mp3" type="audio/mpeg" >
            </audio>

            <script>
                var socket = io.connect("http://localhost:3000");

                $(function() {
                    $('#play').bind('click',function(){
                        alert( "User clicked on 'foo.'" );
                        socket.emit('msg', {sent : 1});
                        return false;
                    });
                });


                socket.on('msg-received', function(data) {
                    if(data.value = 1) {
                        $('#play').click();
                    }
                });
            </script>
        </body>
    </html>

玩
暂停

变量套接字=io.connect(“http://localhost:3000"); $(函数(){ $('#play').bind('click',function(){ 警报(“用户单击“foo.”); emit('msg',{sent:1}); 返回false; }); }); socket.on('msg-received',函数(数据){ 如果(data.value=1){ $(“#播放”)。单击(); } });
如果你将代码精简到你所要求的程度,那么代码就可以正常工作。很可能是代码中的其他内容导致了错误

<!-- Bare-Bones HTML CODE -->
<button type="button" id="play" name="play" value="play">PLAY</button>

// JavaScript
$(function() {
  $('#play').bind('click', function() {
    alert("User clicked on 'foo.'");
    return false;
  });
});

玩
//JavaScript
$(函数(){
$('#play').bind('click',function(){
警报(“用户单击“foo.”);
返回false;
});
});
在浏览器上的web检查器或调试器中是否看到任何错误


下面是一段工作代码(已精简)。

GET jquery-3.1.1.min.js出现404错误,但我将此js文件与上面的html文件放在同一目录中。如果您在jquery上遇到404错误,则表示未加载。