Tag: html

用新条目改变div的值,不要追加

我对编码完全陌生。 请help.I获取tweet文本使用node.js和显示使用HTML。 当我input新的文本时,结果应该replace#tweets中的更早的结果,而不是附加到它 <!DOCTYPE html> <html> <head> </head> <body> <form> #<input type="text" id="tag" class="hash"/> <button>submit</button> </form> <div id="tweets"></div> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js"></script> <script src="/socket.io/socket.io.js"> </script> <script> var socket = io.connect('/link'); $('.hash').on('keypress',function(){ setTimeout(function(){ $('#tweet').empty(); socket.emit('message', $('#tag').val()); },2000); return; }); socket.on('message', function(msg){ $('#tag').val(''); $('#tweet').empty(); $('#tweets').after($('<div>').text(msg)); }); </script> </body> <html>

如何使用nodeJS将脚本文件链接到html文件

我使用nodeJS提供了一些html,但我想能够调用JavaScript文件中的函数,我正在尝试链接。 但是,我收到错误消息Resource interpreted as Script but transferred with MIME type text/html: "http://localhost:8888/index.js" 。 我不知道什么不能正确链接,并需要一种方法来链接我的文件index.js 。 我想要做的是将文件加载到头部,如下所示: http = require('http'), http.createServer(function(req, res) { var body = '<html>'+ '<head>'+ '<script src="index.js"></script>'+ '<meta http-equiv="Content-Type" content="text/html; '+ 'charset=UTF-8" />'+ '</head>'+ '<body>'+ '</body>'+ '</html>'; response.writeHead(200,{"Content-Type":"text/html"}); response.write(body); response.end(); } }).listen(8888); 我怎样才能加载这个JavaScript文件, index.js ,以便包含在index.js中的所有function将在客户端可用?

如何将表单的checkbox分组到Node中的数组中?

我正在尝试用多个checkbox创build一个表单。 我想每个checkbox共享相同的名称,并检查的价值与表格提交。 我知道这可以用PHP来完成(看到这个问题 ),但我不知道如何使用Node.js和Express。 这里是我的HTML的修改版本: <label><input type="checkbox" name="section[]" value="1" />Item Name</label> <label><input type="checkbox" name="section[]" value="2" />Item Name</label> <label><input type="checkbox" name="section[]" value="3" />Item Name</label> 当我处理POST请求时,我试着用req.param('section')和req.param('section[]')访问值,但是它们都返回undefined。

节点jbs模块和引擎

我是新的节点js和碰到这个hbs模块,看到它在这部分代码例如: app.set('view engine', 'html'); app.engine('html', require('hbs').__express); 任何人都可以请解释什么是HBS(把手 – 但它是做什么)? 以及为什么第二行是必要的,如果第一个已经说文件将被打开为html 谢谢!

如何在Node.js中发出事件名称是dynamic的?

我正在尝试在Node.js中创builddynamicEventEmitter。 那么,事件名称怎么可以是dynamic的。 代码: var express = require('express'), app = express(), server = require('http').createServer(app), io = require('socket.io').listen(server); num = "1"; fs = require('fs'); server.listen(4000); function handler(req,res){ fs.readFile(__dirname + '/index.html', function(err,data){ res.writeHead(500); res.end(data); }); } app.get('/', function(req, res){ res.sendfile(__dirname + '/index.html'); }); io.sockets.on('connection', function(socket){ socket.on('send message'+num, function(data){ io.sockets.emit('new message'+num, data); }); }); 现在在这个例子中,我给了值“1”,但我希望它dynamic,所以我怎么能从一个HTML文件的dynamic值。 所以,发出事件名称可以是dynamic的。 请让我知道,build议我一些解决scheme。

填写表格并使用NodeJS访问网页

我想在这个网页http://www.ncbi.nlm.nih.gov/gorf/orfig.cgiinput一个string,点击analyze或类似的HTML (例如点击该网页中的OrfFind )之后,得到在浏览器中输出。 这是可能的NodeJS ?

Javascript彩色显示

我正在尝试使用node.js从js文件创build一个HTML文件! 我的问题是为什么颜色不显示在HTML文件中。 我创build了hex值的string,但在HTML文件中,颜色不显示。 var format; function RND() { var hex = ((Math.floor(Math.random()*0xffffff)+1)).toString(16); while (hex.length < 6) hex = "0" + hex; return "#"+hex; } console.log("<html><head>"); console.log("<meta charset=\"UTF-8\">"); console.log("<title>Ten Random Colors</title>"); console.log("</head>"); console.log("<body>"); console.log("<ul>"); for(var i = 0; i < 100; i++){ var color = RND(); //console.log(color); format="<li style =\""+color+"\">"+color+"</li>"; console.log(format); } console.log("</ul>"); console.log("</body>"); console.log("</html>");

路线404.html为快速应用程序

我已经看到很多post解决这个问题,但似乎没有为我工作,许多解决scheme使用不推荐的方法。 我有静态文件目录已经build立: app.use(express.static(__dirname + "/public", {maxAge: 86400000*30 })); 然后我在该公共目录中有一个自定义的404.html页面。 现在,任何不正确的URL应该被路由到那个404.html页面。 我已经尝试了以下内容: app.use(function(req, res, next){ res.render("404.html", { url: req.url }); }); 但是我得到了回应: Error: Cannot find module 'html' 我做错了什么,为什么这么简单的事情太难了?

无法使用nodeJS在html中设置Image src

我在nodeJS上是新的,我无法在我的客户端html中设置img标签的src。 因为我的节点服务器运行在端口3000上,当我打到http:// localhost:3000时, 下面是我的server.js文件的代码 var app = require('express')(); var http = require('http').Server(app); var io = require('socket.io')(http); app.get('/', function (req, res) { res.sendFile('/var/www/UI-Test/client.html'); }); io.on('connection', function (socket) { console.log('user joined '); }); http.listen(3000, function () { console.log('listening on *:3000'); }); 下面给出了client.html的代码 <html> <body> <img src="f1.png" /> <!– also tried "./f1.png" –> <script> var socket = io(); […]

innerHTML与NodeJS和Jade

我试图改变一个数字的值显示与Jade从Javascript。 我有一个ID号的段落,然后在Javascript中,并尝试改变它使用innerHTML,但没有任何反应。 p#number 0 以上是这个段落是如何在玉石中定义的。 然后我在Javascript中获取元素,并试图改变这样的值。 var number = document.getElementById("number"); number.innerHTML("1"); document.getElementById返回的对象不是null,但是该对象的.value()是未定义的。