代码之家  ›  专栏  ›  技术社区  ›  Julien

expressJs中的堆栈jquery

  •  0
  • Julien  · 技术社区  · 6 年前


    也许这是不可能的,但是我需要在 app.js

    例子:

    应用程序js

    const express = require('express')
    const app = express()
    const $ = global.jQuery = require( 'jquery' );
    
    app.get('/', function (req, res) {
      res.sendFile(path.join(__dirname+'/index.html'));
      $("#click").click(function(e){
            console.log('click');   
        }) 
    })
    
    app.listen(3000, function () {
      console.log('Example app listening on port 3000!')
    })
    

    索引.html

    <!doctype html>
    <html>
    <head>
      <title>Express - Jquery</title>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    </head>
    <body> 
        <button id="click" type="button">Click</button>
    </body>
    </html>
    


    如果有人已经这样做了

    1 回复  |  直到 6 年前
        1
  •  1
  •   David    6 年前

    这个代码属于 客户端 服务器端

    $("#click").click(function(e){
        console.log('click');   
    })
    

    你会把它放在你的 index.html . (或在您的 索引.html

    <!doctype html>
    <html>
    <head>
      <title>Express - Jquery</title>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    </head>
    <body> 
        <button id="click" type="button">Click</button>
    </body>
    <script type="text/javascript">
        $("#click").click(function(e){
            console.log('click');
        });
    </script>
    </html>
    

    推荐文章