Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 电子:复选框不改变值?_Javascript_Html_Electron - Fatal编程技术网

Javascript 电子:复选框不改变值?

Javascript 电子:复选框不改变值?,javascript,html,electron,Javascript,Html,Electron,我已经创建了一个浏览器窗口,它使用一个复选框来打开和关闭自己。但是,只检测到处于true状态的复选框,而不是处于false状态的复选框 以下是我在renderer.js中的代码: const {width, height} = screen.getPrimaryDisplay().workAreaSize; let close = document.querySelector('input[name=open_close]'); close.addEventListener('change',

我已经创建了一个浏览器窗口,它使用一个复选框来打开和关闭自己。但是,只检测到处于
true
状态的复选框,而不是处于
false
状态的复选框

以下是我在renderer.js中的代码:

const {width, height} = screen.getPrimaryDisplay().workAreaSize;
let close = document.querySelector('input[name=open_close]');
close.addEventListener('change', function(event){
  if (this.checked = true) {
  console.log("renderer");
 ipcRenderer.send('expClose',width, height);
  }

  if(this.checked = false) {
 ipcRenderer.send('expOpen',width - 500, height - 450);
  }
});
下面是我的main.js:

ipcMain.on('expClose', function(e,width, height) {
    console.log('closed'); 
      mainWindow.setPosition(width - 75, height - 450);
  });
  
  ipcMain.on('expOpen', function(e,width, height) {
   console.log("opened")
   mainWindow.setPosition(width, height);
      
  });
如果需要,还可以使用我的HTML:

<input type="checkbox" name="setbtn" checked="false" id="settings" class="btnset">

我假设没有检测到错误状态,因为没有记录opened。 非常感谢您的帮助。

请使用
=
(作业)而不是
==
(比较)

if(this.checked=true){
更改为
if(this.checked==true){

if(this.checked=false){
if(this.checked==false){
使用
=
(赋值)而不是
==
(比较)

if(this.checked=true){
更改为
if(this.checked==true){


if(this.checked=false){
if(this.checked==false){
我设法让它与此代码一起工作:

const {width, height} = screen.getPrimaryDisplay().workAreaSize;
let close = document.querySelector('input[name=open_close]');
close.addEventListener('change', function(event){
  console.log("renderer");
 ipcRenderer.send('expClose',width, height);

  if(document.querySelector('input[name=open_close]:checked') !==null ) {
 ipcRenderer.send('expOpen',width - 500, height - 450);
  }
});

我成功地让它使用以下代码:

const {width, height} = screen.getPrimaryDisplay().workAreaSize;
let close = document.querySelector('input[name=open_close]');
close.addEventListener('change', function(event){
  console.log("renderer");
 ipcRenderer.send('expClose',width, height);

  if(document.querySelector('input[name=open_close]:checked') !==null ) {
 ipcRenderer.send('expOpen',width - 500, height - 450);
  }
});

您的复选框应命名为“打开\关闭”,否?@SydneyY我嗯…粘贴了错误的htm,我与它们太相似您的复选框应命名为“打开\关闭”,否?@SydneyY我嗯…粘贴了错误的htm,我与它们太相似谢谢我尝试此代码!谢谢我尝试此代码!