在Atom Shell中加载JavaScript脚本的正确方法是什么?

时间:2015-03-16 13:41:11

标签: javascript jquery html electron

这可能是一个完全愚蠢的问题,但我刚开始使用Atom shell。

我有index.html的登录表单。我在文档中提升了jquery表单验证,如下所示:

 $(function() {
     $('#login-form').validate();
 });

这个脚本在正文结束之前加载:

<script src="global/js/dom-bootstrap.js"></script>

当我使用Atom Shell运行页面时,表单显示正确,验证部分工作。它不提交表单,但没有显示任何验证。然后,当我提交表格一次停留在同一页面上(例如,重新加载页面)一切正常!

包括Bootstrap的tab.js也是如此。起初它不起作用,但在页面重新加载后它工作得很好。

我做错了什么?

这是我的main.js(基于Github的Atom Shell示例):

var app = require('app');  // Module to control application life.
var BrowserWindow = require('browser-window');  // Module to create native browser window.

// Report crashes to our server.
require('crash-reporter').start();

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the javascript object is GCed.
var mainWindow = null;

// Quit when all windows are closed.
app.on('window-all-closed', function() {
  if (process.platform != 'darwin')
    app.quit();
});


// This method will be called when atom-shell has done everything
// initialization and ready for creating browser windows.
app.on('ready', function() {
  // Create the browser window.
  mainWindow = new BrowserWindow({
    icon                : 'global/images/logo.png',
    transparent         : true,
    frame               : false,
    "min-width"         : 520,
    "min-height"        : 850,
    fullscreen          : true,
    resize              : true,
    "use-content-size"  : true
  });

  mainWindow.webContents.on('did-finish-load', function() {

  });

  // and load the index.html of the app.
  mainWindow.loadUrl('file://' + __dirname + '/index.html');

  // Emitted when the window is closed.
  mainWindow.on('closed', function() {
    // Dereference the window object, usually you would store windows
    // in an array if your app supports multi windows, this is the time
    // when you should delete the corresponding element.
    mainWindow = null;
  });
});

0 个答案:

没有答案