Node.js按钮onclick功能不起作用

时间:2016-03-30 03:11:57

标签: javascript html node.js onclick

我正在使用node.js创建一个网站 我想在点击按钮时显示“Hello World” 但它不能正常工作。
这是我的代码。

http = require('http');
var onRequest = function(req, res){

    res.writeHead(200, {'Content-Type': 'text/html;charset=utf-8'});

    res.write('<script language="JavaScript">');
    res.write('function func(btn){ alert("Hello World"); }')
    res.write('</script>');

    res.write('<button ');
    res.write('name="btn1" onclick="func(btn1)" style="height:60px;width:60px"> button ');
    res.write('</button>');

    res.end();

};

var server = http.createServer(onRequest);
server.listen(port, ip);

这是Google Chrome中的资源:

<body>

    <script language="JavaScript">
        function func(btn){ alert("Hello World)"}
    </script>

    <button name="btn1" onclick="func(btn1)" style="height:60px;width:60px"> button</button>

</body>

网站成功显示按钮 但是当我点击按钮时它没有显示“Hello World”。为什么呢?

0 个答案:

没有答案
相关问题