【发布时间】:2017-05-12 02:36:59
【问题描述】:
当我点击播放按钮时,警告 - '用户点击了 '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>
【问题讨论】: