第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何構(gòu)建包含條件的數(shù)組

如何構(gòu)建包含條件的數(shù)組

倚天杖 2021-12-12 11:05:22
我需要構(gòu)建一個窗口偵聽器,該偵聽器mouseover在使用的盒子上觸發(fā),但contains我不太確定如何構(gòu)建它?這是我建立的一個測試:window.addEventListener("mouseover", trial)function trial(e) {  const contain_material = document.getElementsByClassName("item")  if(contain_material.contains(e.target)) {    alert("so far so good")  }  else {    return  }}
查看完整描述

3 回答

?
慕村9548890

TA貢獻1884條經(jīng)驗 獲得超4個贊

看看以下是否適合你。


function trial(e) {

  const contain_material = document.getElementsByClassName("item")

  for (var i = 0; i < contain_material.length; i++) {

    if(contain_material[i] == e.target) {

      alert("so far so good")

    }

  }

}


查看完整回答
反對 回復(fù) 2021-12-12
?
繁星點點滴滴

TA貢獻1803條經(jīng)驗 獲得超3個贊

你不能只聽鼠標(biāo)懸停在框元素上而不是整個頁面上嗎?


function handleMouseOver() {

  alert('so far so good')

}


// or you can add dynamicaly with js


var boxes = document.getElementsByClassName("item");

Array.from(boxes).forEach(function() {

  this.onmouseover = () => alert('so far so good')

})


// () => this is an arrow function in case you dont know

// Array.from() is because you can't use the forEach straight with a HTMLCollection

body {

  display: flex;

}


.item {

  width: 300px;

  height: 300px;

  background-color: yellow;

  margin: 10px;

}

<!DOCTYPE html>

<html>


<head>

  <meta charset="UTF-8">

  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <meta http-equiv="X-UA-Compatible" content="ie=edge">

  <title>Document</title>

</head>


<body>

  <div class="item" onmouseover="handleMouseOver()"></div>

  <div class="item" onmouseover="handleMouseOver()"></div>

  <div class="item" onmouseover="handleMouseOver()"></div>

  <div class="item" onmouseover="handleMouseOver()"></div>

</body>


</html>


查看完整回答
反對 回復(fù) 2021-12-12
?
三國紛爭

TA貢獻1804條經(jīng)驗 獲得超7個贊

與其檢查窗口上的懸停,為什么不檢查這些元素之一何時懸停在上面。例如:


const contain_material = document.getElementsByClassName("item")

for (mat of contain_material) {

  mat.addEventListener("mouseover", trial)

}

function trial(e) {

  alert("so far so good")  

}


查看完整回答
反對 回復(fù) 2021-12-12
  • 3 回答
  • 0 關(guān)注
  • 192 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號