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

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

js如何控制input添加類名

js如何控制input添加類名

笑三笑 2016-02-23 20:54:17
因?yàn)槲也欢甁Query,所以我只會(huì)用純JS寫,我的目的是當(dāng)input獲得焦點(diǎn)后,為上面id為"inputGroup"的div添加一個(gè)類名focus,當(dāng)失去焦點(diǎn)時(shí),移除類名focus..在JS里我是這樣寫的最后失敗了,求大神指點(diǎn)。
查看完整描述

2 回答

已采納
?
李曉健

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

<!doctype>
<html>
<head>
????<meta?charset?=?"utf-8">
????<title>xxxxx</title>
????<style?type="text/css">
????????.focus{
????????????border:?1px?solid?red;
????????}
????</style>

</head>
<body>
<div?class="input-group"?id="inputGroup">
????<input?type="search"?onblur="inputOnBlur()"?id="searchInput"?onfocus="inputOnfocus()"?class="form-control"?placeholder="search">
</div>
<script>
????var?searchInput?=?document.getElementById('searchInput');
????var?inputGroup?=?document.getElementById('inputGroup');

????function?inputOnfocus(){
????????inputGroup.classList.add('focus');
????}
????function?inputOnBlur(){
????????inputGroup.classList.remove('focus');
????}
</script>
</body>
</html>

請(qǐng)?jiān)赾hrome或IE10以上的瀏覽器上做測(cè)試

查看完整回答
1 反對(duì) 回復(fù) 2016-02-23
?
慕無忌5553096

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

$("#searchInput").focus(function(){
??$("#searchInput").addClass("focus");
});


查看完整回答
反對(duì) 回復(fù) 2016-02-24
  • 2 回答
  • 1 關(guān)注
  • 3516 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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