我正在學習node.js和socket.io,我正在使用示例。所有的工作,但 所有的jQuery的追加不工作,即使是簡單的像JQuery附加不工作在一個非常簡單的情況下
$("#messages").append("<p>someone said: </p>");
jQuery是加載:
$.fn.jquery
"1.11.1"
這是整個的index.html:
<!doctype html>
<html ng-app="chatapp">
<head>
<title>Socket.IO chat app</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font: 13px Helvetica, Arial; }
form { background: #000; padding: 3px; position: fixed; bottom: 0; width: 100%; }
form input { border: 0; padding: 10px; width: 90%; margin-right: .5%; }
form button { width: 9%; background: rgb(10, 24, 255); border: none; padding: 10px; }
#messages { list-style-type: none; margin: 0; padding: 0; }
#messages li { padding: 5px 10px; }
#messages li:nth-child(odd) { background: #eee; }
</style>
</head>
<body>
<ul id=messages">Messages: </ul>
<form action="">
<input id="m" autocomplete="off" />
<button>Send</button>
</form>
<script src="/socket.io/socket.io.js" type="text/javascript"></script>
<script src="https://code.jquery.com/jquery-1.11.1.js" type="text/javascript"></script>
<script> $(document).ready(function(){ $("#messages").append("<p>Initializing... </p>"); });</script>
<script type="text/javascript">
$(function() {
var socket = io();
$('form').submit(function(){
socket.emit('chat message', $('#m').val());
$('#m').val('');
return false;
});
socket.on('chat message', function(msg){
console.log('incoming: ' + msg);
$("#messages").append("<p>someone said: </p>");
console.log('second append ');
$('#messages').append($('<li></li>').text("hola"));
});
socket.on('connection', function() {
console.log("client connected");
});
socket.on('connect_error', function(err) {
console.log("client connect_error: ", err);
});
socket.on('connect_timeout', function(err) {
console.log("client connect_timeout: ", err);
});
});
</script>
</body>
</html>
見那
<script> $(document).ready(function(){$("#messages").append("p>Initializing... </p>"); });</script>
也沒有顯示。
有什麼想法?
您的p標籤缺少開口< – Keith