【问题标题】:change button onmouseover to onclick将按钮 onmouseover 更改为 onclick
【发布时间】:2020-01-17 08:44:19
【问题描述】:
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 打开/关闭吗?谢谢!

【问题讨论】:

  • 你尝试过什么吗?
  • changeButton.onclick 不适合您?
  • 如果我只是更改为 onclick 它也会关闭 onclick 而无需任何其他操作?
  • 你的意思是你想让它切换?你试过onclick吗?

标签: javascript button onclick mouseover


【解决方案1】:

只需将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();
   });

【讨论】:

  • 它也会关闭 onclick 吗?我无法检查
猜你喜欢
  • 1970-01-01
  • 2019-06-02
  • 1970-01-01
  • 2023-01-14
  • 2015-01-12
  • 2012-05-27
  • 2013-09-12
  • 1970-01-01
相关资源
最近更新 更多