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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

為什么事件模糊不能與函數(shù)名稱模糊一起使用?

為什么事件模糊不能與函數(shù)名稱模糊一起使用?

慕慕森 2023-07-06 10:07:56
當(dāng)我嘗試使用相同的函數(shù)名稱模糊將事件(特別是“模糊”)添加到 HTML 時(shí),為什么它不起作用但是當(dāng)我使用另一個(gè)函數(shù)名稱(例如模糊或 abc)時(shí)function abc(element){  element.style.background="lime"}function blur(element){  element.style.background=""}<!DOCTYPE html><html><head>  <meta charset="UTF-8">  <meta name="viewport" content="width=device-width, initial-scale=">  <title></title></head><body>  <form action="">    <label for="">Name</label> <input type="text" id="fname" onfocus="abc(this)" onblur="blur(this)">    <br><br>    <label for="">class</label> <input type="text" onfocus="abc(this)" onblur="blur(this)">    <br><br>    <label for="">Country</label>    <select name="" id="">      <option value="">Pakistan</option>      <option value="">India</option>      <option value="">America</option>      <option value="">China</option>    </select>          </form>  </body></html>或任何其他名稱它開(kāi)始工作。有人能告訴我為什么嗎?
查看完整描述

2 回答

?
汪汪一只貓

TA貢獻(xiàn)1898條經(jīng)驗(yàn) 獲得超8個(gè)贊

有一個(gè)非常優(yōu)雅的解決方案 - 不使用 javascript,而是使用 css 偽類焦點(diǎn):

:focus CSS 偽類表示已接收焦點(diǎn)的元素(例如表單輸入)。它通常在用戶單擊或點(diǎn)擊某個(gè)元素或使用鍵盤(pán)的 Tab 鍵選擇它時(shí)觸發(fā)。

在你的情況下:

.lime-focused-input:focus {

? ? background:lime;

}

<!DOCTYPE html>

<html>

<head>

? <meta charset="UTF-8">

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

? <title></title>

</head>

<body>

? <form action="">

? ? <label for="">Name</label> <input type="text" id="fname" class="lime-focused-input">

? ? <br><br>

? ? <label for="">class</label> <input type="text" class="lime-focused-input">

? ? <br><br>

? ? <label for="">Country</label>

? ? <select name="" id="">

? ? ? <option value="">Pakistan</option>

? ? ? <option value="">India</option>

? ? ? <option value="">America</option>

? ? ? <option value="">China</option>

? ? </select>

? </form>

</body>

</html>


查看完整回答
反對(duì) 回復(fù) 2023-07-06
?
鳳凰求蠱

TA貢獻(xiàn)1825條經(jīng)驗(yàn) 獲得超4個(gè)贊

我想如果您嘗試使用background透明更改 try 并且不要使用blur,它是一個(gè)沖突的關(guān)鍵字(原因見(jiàn)下文):


function abc(element) {

  element.style.background = "lime";

}


function aaa(element) {

  element.style.backgroundColor = "transparent";

}

<form action="">

  <label for="">Name</label> <input type="text" id="fname" onfocus="abc(this)" onblur="aaa(this)">

  <br><br>

  <label for="">class</label> <input type="text" onfocus="abc(this)" onblur="aaa(this)">

  <br><br>

  <label for="">Country</label>

  <select name="" id="">

    <option value="">Pakistan</option>

    <option value="">India</option>

    <option value="">America</option>

    <option value="">China</option>

  </select>

</form>

默認(rèn)情況下,作用域是window作用域,window.blur()或者blur()是對(duì)象的事件處理程序window,并且不能被覆蓋。

http://img1.sycdn.imooc.com//64a622340001366a02080037.jpg

因此您無(wú)法覆蓋任何這些window相關(guān)屬性。


查看完整回答
反對(duì) 回復(fù) 2023-07-06
  • 2 回答
  • 0 關(guān)注
  • 153 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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