当我点击播放按钮时,警告 - '用户点击'foo'必须已经显示,但那不会发生。即没有调用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>
答案 0 :(得分:0)
如果你把它删除到你要问的代码,那么代码工作正常。最有可能的是,代码中的其他内容会导致错误。
<!-- 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;
});
});
您是否在浏览器上看到Web检查器或调试器中的任何错误?
这里是codepen工作代码(已剥离)。