跳到主要内容
CNode

node-webkit中如何用DOM事件调用node模块

社区
Jjabez128发布于 12 年前最后回复 12 年前
363820

比如说用一个click事件调用fs模块中的writeFile函数?试了一下似乎是不行,但是也没报错。。。感觉很奇怪

查看回复

回复 (3)

A
airbob#312 年前
引用 gitchs最简单的

writeFile后面加上输出的绝对路径再试试,比如

fs.writeFile("/Users/abc/Desktop/dbug/result.txt","hello world");

不加的话也写入成功了,只是写入的不是你project的那个目录下。 也可以加fs.writeFile("result.txt", "hello world", function(err) {if(err){alert(err);}}); 调试。

G
gitchs#212 年前

最简单的

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf8">
	<title></title>
</head>
<body>
	<button onclick="writeFile()">Click</button>
	<script type="text/javascript">
		var writeFile = function(){
			var fs = require('fs');
			fs.writeFile("result.txt","hello world");
		}
	</script>
</body>
</html>
A
airbob#112 年前

应该可以的,发下source code? 或下载最新版node-webkit 再试一下。

参与回复

登录后即可参与回复。登录