We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
第190天 用原生js实现类似getElementsByClassName的方法,不能使用querySelectorAll
The text was updated successfully, but these errors were encountered:
function getElementsByClassName(className) const tags = document.getElementsByTagName('*'); const tempTags = []; for(let i=0, len = tags.length; i< len; i++) { let tag = tags[i]; tag.classList.contains(className) && tempTags.push(tag) } return tempTags; }
Sorry, something went wrong.
实现的方式有很多种,楼上用了document.getElementsByTagName, 那我这里就用document.all
//正则实现
function getElementsByClassName(className){ const tags = document.getElementsByTagName('*'); const reg = new RegExp("\\b" + className + "\\b"); const tempTags = []; for(let i=0, len = tags.length; i< len; i++) { let tag = tags[i]; reg.test(tag.className) && tempTags.push(tag) } return tempTags; }
No branches or pull requests
第190天 用原生js实现类似getElementsByClassName的方法,不能使用querySelectorAll
The text was updated successfully, but these errors were encountered: