electronjs总是在单击按钮后刷新

electronjs总是在单击按钮后刷新,electron,Electron,我正在使用electron构建桌面应用程序,当我单击任何按钮时,它会刷新整个应用程序,我需要防止这种刷新 <script> window.$ = window.jQuery = require('jquery') $(function(){ var config = require('../jsonFiles/pathData.json'); $("#aspnetCorePathRename").val(config.Aspne

我正在使用electron构建桌面应用程序,当我单击任何按钮时,它会刷新整个应用程序,我需要防止这种刷新

  <script>
    window.$ = window.jQuery = require('jquery')
    $(function(){
    var config = require('../jsonFiles/pathData.json');
    $("#aspnetCorePathRename").val(config.AspnetCorePath);
    $("#angularPathRename").val(config.AngularPath);
    });
    function ren(e) {
        const fs = require("fs");
        fs.readFile('./scrips/Rename.ps1', function (err, data) {
        if (err) {

            $(".Console").html(err.toString());
            alert(err.toString());
            return console.error(err);

        }
        alert(data.toString());
        });
        readFile();

  

    }

    </script>

window.$=window.jQuery=require('jQuery')
$(函数(){
var config=require('../jsonFiles/pathData.json');
$(“#aspnetcorepathname”).val(config.AspnetCorePath);
$(“#angularPathRename”).val(config.AngularPath);
});
职能部门(e){
常数fs=要求(“fs”);
fs.readFile('./scrips/Rename.ps1',函数(err,data){
如果(错误){
$(“.Console”).html(err.toString());
警报(err.toString());
返回控制台。错误(err);
}
警报(data.toString());
});
readFile();
}

这很可能不是electron或您的脚本的问题,而是您在HTML中定义按钮的方式的问题。如果您这样定义它:

HTML假定它是表单的“发送”按钮,并将刷新页面。如果您将其定义为按钮

提交

页面将不会刷新

如果必须将其定义为输入,我假设您可以防止jQuery的默认行为,如下所示:


$(“输入[type='submit'])。单击(函数(){return false;})

我的按钮在HTML中定义如下。在这种情况下,HTML似乎是正确的(除了它应该是
onclick
而不是
onclick
)。您可以尝试将`event.preventDefault()`设置为该按钮,以查看触发重新加载的是您的脚本还是某些默认行为。