将鼠标从鼠标悬停更改为鼠标单击

问题描述 投票:0回答:1
changeButton.className = 'change button types-popup';
const changePopup = document.createElement('div');
changeButton.appendChild(changePopup);
changeButton.onmouseover = e => {
   if (!e.target.classList.contains('types-popup')) return;
   changePopup.innerHTML = '':
   renderTypes(changePopup, type => {
       defectData.action = 'update';
       defectData.type = type.id;
       textDiv.children[0].innerText = type.description;
       closePopups();
   });

我完全不了解js。因此,您可以帮我将onmouseover更改为onclick打开/关闭吗?谢谢!

javascript button onclick mouseover
1个回答
0
投票

只需将changeButton.onmouseover更改为changeButton.onclick

请参见onclick

changeButton.className = 'change button types-popup';
const changePopup = document.createElement('div');
changeButton.appendChild(changePopup);
changeButton.onclick = e => {
   if (!e.target.classList.contains('types-popup')) return;
   changePopup.innerHTML = '':
   renderTypes(changePopup, type => {
       defectData.action = 'update';
       defectData.type = type.id;
       textDiv.children[0].innerText = type.description;
       closePopups();
   });
© www.soinside.com 2019 - 2024. All rights reserved.