【问题标题】:jQuery not working with SemanticUI and Electron.jsjQuery 不适用于 SemanticUI 和 Electron.js
【发布时间】:2020-07-02 02:38:03
【问题描述】:

我一直在尝试在我的 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>

但似乎没有一个工作。我试过用 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>

【问题讨论】:

  • 你能解释一下“不工作”是什么意思吗?与预期相反的具体情况是什么?如果你打开 Electron 窗口的开发者工具,我会很有帮助,这样你就可以看到网络请求和控制台错误。

标签: jquery html node.js electron semantic-ui


【解决方案1】:

在您的index.html

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

还有createBrowerWindownodeIntegration 在你的main.js

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

【讨论】:

  • 成功了!谢谢!
猜你喜欢
  • 2018-10-21
  • 2019-08-28
  • 2016-08-09
  • 2014-02-09
  • 2013-04-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-25
相关资源
最近更新 更多