为了账号安全,请及时绑定邮箱和手机立即绑定

为什么显示是1 跟 0

为什么显示是1 跟 0

阿尼加得 2019-01-09 13:11:22
<!DOCTYPE html><html><head><meta charset="utf-8" /><meta http-equiv="X-UA-Compatible" content="IE=edge"><title>Page Title</title><meta name="viewport" content="width=device-width, initial-scale=1"><script>window.onload = function() {var len1 = getByClass('on', 'list');alert(len1.length); // 结果等于2为正确var len2 = getByClass('on');alert(len2.length); // 结果等于3为正确}function getByClass(clsName, parent) {//定义函数getByClassvar oP = parent ? document.getElementById(parent) : document;//是一个判断语句,如果传入parent即parent存在,那么var op = document.getElementById(parent),不存在的话就是var op = documentvar a = oP.getElementsByTagName('*');var b = new Array();for (var i = 0; i < a.length; i++) {if (a[i].className == clsName) {b.push(a[i]);}return b;}}</script></head><body><ul id="list"><li class="on">1</li><li class="select">2</li><li class="on">3</li><li>4</li></ul><p class="on">class为on的p标签</p></body></html>
查看完整描述

1 回答

?
__innocence

TA贡献313条经验 获得超208个赞

return b 需要放在for循环外面。


查看完整回答
1 反对 回复 2019-01-09
?
慕瓜9220888

TA贡献868条经验 获得超0个赞

LMIRTGMPM

TBDYHKAXE

WXZRBEBEI

TEQIUBBVR

HVUZQNQDJ

ODIBTGDGN

QSWVISTGN

LAVBAWJYW

KQQSUXKXU

XIKPOBRTG

INMBAXDDK

TSAWYIOHS

GFRMMZZJP

WLTPDGTQT

EGEHURIOR

YEKWISGDK

PTPRQHUMJ

VAFSLFYFV

CUASORKOR

MRZHLDQGQ

VMLXICRUX

JQSRQJQTW

DEXJBOFFV

FMVRMZCJM

HMLHSHRKN

EHDJSZAXE

JLTRZWZEA

OTQSXANKX

FNPAIZZPC

JYCIURERA

YJJOEHKXK

WLXFBYNTB

SEGFOXPGT

TSBNSJGAD

EQQCNRKDK

FAGNTWTZW

PADLNANCP

NLHQSVLFI

APRAVISYF

SACRTWMZZ

UJBUZJMZW

ZYGCHKEBR

BENZIEYLL

FTZFADQUH

KJZJZMDRE

DLHZNADGN

MEGIEJMZN

WIYDWJPSW

XVUCIBUYE

VAMGCVPSF

TZBWSCPSS

LINWROBYS

SOXZIYLOB

GRDPLELOR

WBWZORKZD

FUWBKXXAU

YWVEDHXPC

HJJTZNERP

TOQMRBUHU

LJVXZMWDZ

HZBDCDMTJ

DSHERUQUQ

ARNWYLELP

SXKWSFYOL

TJPUDTMTW

JVHJBOJMH

FXMFRERXB

YEXCOLOBF

RZSNGTZJN

ASKWPSVSY

LVIIQFSFP

ONIHTGZMR

XFOQLVCFI

TIKMORXKO

XZPHTZPIF

ZRDMCCURX

RJYEBVAIP

PEQWBFLPL

JZTFBEYLI

ZOHCYLORI

UZKGCZXNX

RRHCEXURU

BGSEJUHLB

ZRWBXUHYL

CLBGCYPJX

SHZVTQDIP

XSUQLOSFS

ODJEDGJWA

SXDOHXYCZ

BGIEATGBE

LGZOQDGDK

OWWVAXOIL

OTFRGJYVP

HGPHKNURO

ZBOTDXLIF

TOKJEBWTD

KQJVAKXAQ

YZVHZUAEH

WAPPAEXEC

RJONSJTPW

FPPBZNHOS

HMMRKXIFC

BMIENAAVZ

WHNCOBEZM

GHJOKHHUE

XVXKJMWCP

CDALURUBE

WRKGIVSLO

GEWPEHAXU

OGYKPUHUZ

VGSLGTQOR

PKCVQKXNA

KLQPEYBHK

WXJLSIVOI

APCVXUXUK

PALXADADA

WXAVKXKRU

YDMRNTFBV

LTSEQWJQK

RSBOALAEO

GLWSEHUXE

CXFJFILSF

RCRQWTGTG

LGBOAHKXD

WEJCYMGDJ

HMEQMVFLI

BTGVHEJPT

FACOQDXDQ

NVXPBOVEI

PQKVEXNAN

PHZBHXBXB

BKGINQCFS

USBNRNHER

JEGNZURER

KFRWPCZVF

BAWYDPCZV

XUGYAHREA

MHZLBYFJV

KRNGWNHEH

KMODDHDKQ

SQNNDZTGG

TLTVRAEUE

YDPOJEVEV

KZBTFSFSB

GYJLXKHHU

LMOAGDQTG

EJSKMCZKR

GEWOQVPCV

MXZIDXFSS

SDNZURKRU

GSCUQDJWW

SXDJVIURU

QSACFBSSM

NENIQQQDX

GRKZOHLJZ

ABNMIBEZD

LNFKMZDTQ

STFKTWORO

AHWVHXKXH

BKVLXKXJR

RACBJNJIF

GBRGMZJMS

OHVVHKHNI

CMUTPCZVM

GEKCYVOLY

KSXGSQQND

XFXWLOSIG

QRHCYFVKX

TSLHXBKXK

ROZVRKEUX

FTCJCPCIF

AVWIANGTG

ZOMFKKKKH

GGFHQLROL

SEWYKNQDC

PLNTOIBOI

GYAFHHHKN

IGFREHOHO

PUWRATTWB

UPIURLOEE

查看完整回答
反对 回复 2021-10-20
  • 1 回答
  • 1 关注
  • 1251 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信