由于某种原因,此脚本不起作用。我正在使用 express、socket.io、jade 和 node.js。这是脚本:
var socket = io.connect();
function addMessage(msg)
{
var currentDate = new Date();
var dateTime = currentDate.getDate() + "/" +
(currentDate.getMonth() + 1) + "/" +
currentDate.getFullYear() + "@"
currentDate.getHours() + ":" +
currentDate.getMinutes() + ":" +
currentDate.getSeconds();
$("#historyView").append("<p>" + dateTime + " - " + msg + "</p>");
}
function sentMessage()
{
if ($("#arduinoInput").val() != "")
{
socket.emit("message", $("#arduinoInput").val());
addMessage($('#arduinoInput').val(), new Date().toISOString(), true);
$("#arduinoInput").val("");
}
}
socket.on("message", function(message){
addMessage(message);
});
$document.ready(function(){
$("#submit").click(function(){
sentMessage();
});
});
它甚至不清除文本框。这是玉页:
doctype 5
html
head
title Arduino Controller 2
script(src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js")
script(src="/socket.io/socket.io.js");
script(src="script.js")
link(rel="stylesheet" type="text/css" href="style.css")
body
div.container
header
h1 Arduino Controller 2
center
div#historyView
input(type="text")#arduinoInput
button#submit Send
我一直在尝试调试这个。如果有帮助,我将在 Mac OS X 10.9 上运行它。