亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

如何讓一個js代碼適用于一個div的所有classname?

如何讓一個js代碼適用于一個div的所有classname?

幽蟬鳴泣之時 2016-11-05 21:15:59
這是HTML<div class="content_box" id="content_box">?? ??? ??? ??? ??? ?<div class="content_intro" id="content_intro">?? ??? ??? ??? ??? ??? ?<h3>所向披靡的響應式開發</h3>?? ??? ??? ??? ??? ??? ?<p>忘記設備尺寸,一套代碼適應多終端,響應式開發讓用戶體驗和開發效率完美結合</p>?? ??? ??? ??? ??? ?</div>?? ??? ??? ??? ??? ?<div class="content_bottom">?? ??? ??? ??? ??? ??? ?<span class="1 color-red">¥128.00</span>?? ??? ??? ??? ??? ??? ?<span class="r">1560人在學</span>?? ??? ??? ??? ??? ?</div>?? ??? ??? ??? ?</div>??? css.content_box{?? ?width: 200px;?? ?height: 148px;?? ?overflow: hidden;?? ?position: relative;?? ?background-image: url(../image/list1.jpg);}.content_intro{?? ?box-sizing: border-box;?? ?padding: 0 20px;?? ?top: 74px;?? ?height: 129px;?? ?width: 100%;?? ?background-image: url(../image/bd.png);?? ?position: absolute;}.content_bottom{?? ?padding: 0 20px;?? ?bottom: 0;?? ?box-sizing: border-box;?? ?width: 100%;?? ?height: 37px;?? ?background-color: #fff;?? ?color: #93999f;?? ?font-size: 12px;?? ?position: absolute;}.color-red{?? ?color: #EF1300 !important;?? ?float: left;?? ?}?? ?.r{?? ?float: right;}.content_intro h3{?? ?height: 38px;?? ?color: #14191e;?? ?font: 14px "微軟雅黑";?? ?line-height: 38px;}.content_intro p{?? ?color: #93999f;?? ?font-size: 12px;?? ?height: 35px;?? ?overflow: hidden;}這是jswindow.onload = function(){?? ??? ??? ?var content_box=document.getElementsByName("content_box");?? ??? ??? ?content_box.onmouseover=function(){?? ??? ??? ??? ?move();?? ??? ??? ?}?? ??? ??? ?content_box.onmouseout=function(){?? ??? ??? ??? ?move1();?? ??? ??? ?}?? ??? ?}?? ??? ??? ?var timer=null;?? ??? ??? ?function move(){?? ??? ??? ??? ??? ?clearInterval(timer);?? ??? ??? ??? ?var hidden = document.getElementsByName("content_intro");?? ??? ??? ??? ?timer=setInterval(function(){?? ??? ??? ??? ??? ?if(hidden.offsetTop==19 ){?? ??? ??? ??? ??? ??? ?clearInterval(timer);?? ??? ??? ??? ??? ?}else{?? ??? ??? ??? ??? ?hidden.style.top=hidden.offsetTop-1+"px";?? ??? ??? ??? ??? ?}?? ??? ??? ??? ?},10)?? ??? ??? ?}?? ??? ??? ?function move1(){?? ??? ??? ??? ??? ?clearInterval(timer);?? ??? ??? ??? ?var hidden = document.getElementsByName("content_intro");?? ??? ??? ??? ?timer=setInterval(function(){?? ??? ??? ??? ??? ?if(hidden.offsetTop>=74 ){?? ??? ??? ??? ??? ??? ?clearInterval(timer);?? ??? ??? ??? ??? ?}else{?? ??? ??? ??? ??? ?hidden.style.top=hidden.offsetTop+1+"px";?? ??? ??? ??? ??? ?}?? ??? ??? ??? ?},10)?? ??? ??? ?}?? ??? ?</script>我是要用到多個,所以獲取ID的方法不適用? 怎么可以獲取ClassName來實現獲取ID的效果?
查看完整描述

3 回答

?
qq_小盛開_0

TA貢獻31條經驗 獲得超3個贊

document.getElementsByClassName()可以用 ? ?但IE8以下不支持,

document.querySelectorAll("標簽元素或者className"),返回所有有這個的標簽元素或者className的元素的數組

查看完整回答
反對 回復 2016-11-06
?
趙小妖么么噠

TA貢獻44條經驗 獲得超26個贊

document.getElementsByClassName()

這句話可以獲得所有相同的class。

采納一下。謝謝\(^o^)/~

查看完整回答
反對 回復 2016-11-06
  • 3 回答
  • 0 關注
  • 1753 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號