我调用Socket.io函数和Uncaught TypeError:undefined不是一个函数

我正在做socket.io聊天应用程序,并在JavaScript中遇到麻烦。

这是我的JavaScript文件(客户端)

<script src="https://cdn.socket.io/socket.io-1.2.0.js"></script> <script src="https://code.jquery.com/jquery-1.10.2.js"></script> <script> $(document).ready(function() { // make a new chat div $("#topic_button").click(function(e) { e.preventDefault() var domElement = $('<div class="content"><div class="messages"><ul class = "other_message" class="title"><h3>'+$("#m").val()+'</h3></ul>'+'상대방'+'<div class="my_message">'+'내메시지' +'</div></div><div class="type_div"><form action="" class="chat_form" onsubmit="event.preventDefault();"><input autocomplete="off" /><button class="chat_button">Send</button></form></div></div>'); $("#content").after(domElement); }); // create a new category $("#topic_button").click(function(e){ var $item = $('<div class="item_div"><li>' + $("#m").val() + '</li><button class="item_button">X</button><div></div></div>') $('#category').append($item); $('#m').val(''); }); // delete category $("#category").on("click", ".item_button", function () { var title = $(this).prev().html(); $( "h3:contains("+title+")" ).parents(".content").remove(); $(this).parent().slideUp(); }); var socket = io(); $('body').on("submit", ".chat_form", function(){ socket.emit('chat message', $('.chat_form').firstChild().val()); $('.chat_form').firstChild().val(''); return false; }); socket.on('chat message', function(msg, reply){ $('.other_message').append($('<li>').text(reply + ': ' + msg)); }); socket.on('test channel', function(msg, sender){ $('.my_message').append($('<li>').text(sender + ': ' + msg)); }); }); </script> 

和At

 $('body').on("submit", ".chat_form", function(){ socket.emit('chat message', $('.chat_form').firstChild().val()); $('.chat_form').firstChild().val(''); return false; }); 

“socket.emit('chat message',$('。chat_form')。firstChild()。val());”带来Uncaught TypeError:undefined不是函数

我认为这是关于JavaScript的问题。 有人可以帮助我吗?