jQuery 无法使用 SemanticUI 并且 Electron.js

jQuery not working with SemanticUI and Electron.js

我一直在尝试在我的 HTML 中为 Electron 应用程序使用语义 UI。我能够加载元素,但由于某种原因我不能使用 jQuery。我已经尝试了我的本地 jQuery 副本:

<script src="node_modules/jquery/dist/jquery.min.js"></script>

CDN版本:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

但 none 似乎有效。我试过用 jQuery 做一些简单的事情,但仍然没有用。任何帮助,将不胜感激。我更愿意使用我的本地副本。

<!DOCTYPE html>
<html lang="en">
   <head>
      <meta charset="utf-8">
      <title>Title</title>

      <link rel="stylesheet" type="text/css" href="semantic/dist/semantic.min.css">
      <!-- <script src="node_modules/jquery/dist/jquery.min.js"></script> -->
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
   </head>

   <body>
      <div class="ui sidebar inverted vertical menu">
         <a class="item">1</a>
      </div>

      <div class="pusher">
         <h1 class="asdf" id="asdf">Hello</h1>
      </div>


      <script>
         document.getElementById("asdf").innerHTML = "new1";
         $('#asdf').text("new2");
         $('#asdf').html("new2");
      </script>
      <script src="semantic/dist/semantic.min.js"></script>

   </body>

</html>

在你的index.html

  <head>
    <script>
      window.$ = window.jQuery = require("jquery");
    </script>
    ....

并且 createBrowerWindownodeIntegration 在您的 main.js

const mainWindow = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      nodeIntegration: true
    }
  })