Javascript> HTML吐出纯文本

时间:2016-01-29 23:14:12

标签: javascript jquery html ubuntu

我有一个小问题,但我自己无法找到问题:/

所以我有一小部分代码:

<html>
<head>
  <title>Chat</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(130,224,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"></ul>
<form action="">
<input id="m" autocomplete="off"/><button>Send</button>
</form>

<script src="https://cdn.socket.io/socket.io-1.4.5.js"></script>
<script src="http://code.jquery.com/jquery-1.11.1.js"></script
<script>
var socket = io();
$('form').submit(function(){
    socket.emit('chat message', $('#m').val());
    $('#m').val('');
    return false;
});
socket.on('chat message', function(msg){
    $('#messages').append($('<li>').text(msg));
});
</script>
</body>
</html>

但是,<script></script>之间的部分var var = io(); 开始正在以纯文本的形式吐出......

enter image description here

我找不到问题,也许你们其中一个人知道......

谢谢!

3 个答案:

答案 0 :(得分:4)

您错过了>

<script src="http://code.jquery.com/jquery-1.11.1.js"></script

应该是:

<script src="http://code.jquery.com/jquery-1.11.1.js"></script>

答案 1 :(得分:1)

这一行就在这里:

<script src="http://code.jquery.com/jquery-1.11.1.js"></script

>

之后缺少结束</script

var socket = io();
$('form').submit(function() {
  socket.emit('chat message', $('#m').val());
  $('#m').val('');
  return false;
});
socket.on('chat message', function(msg) {
  $('#messages').append($('<li>').text(msg));
});
* {

  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(130, 224, 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;

}
<html>

<head>
  <title>Chat</title>

</head>

<body>

  <ul id="messages"></ul>
  <form action="">
    <input id="m" autocomplete="off" />
    <button>Send</button>
  </form>

  <script src="https://cdn.socket.io/socket.io-1.4.5.js"></script>
  <script src="http://code.jquery.com/jquery-1.11.1.js"></script>
</body>

</html>

答案 2 :(得分:0)

结束script代码缺少>

尝试:

<script src="http://code.jquery.com/jquery-1.11.1.js"></script>