There is no way to get class in js. I have found some encapsulated methods. Here is a sorting
(1) Package first
//Encapsulate getClass function getClass(tagName,className) //Get the element with the tag name tagName and class name className{ if(document.getElementsByClassName) //Support this function{ return document.getElementsByClassName(className); } else { var tags=document.getElementsByTagName(tagName);//Get the tag var tagArr=[];//Use to return the element with the class name className for(var i=0;i < tags.length; i++) { if(tags[i].class == className) { tagArr[tagArr.length] = tags[i];//Save elements that meet the conditions} } return tagArr; } }(2) Main program
<ul> <li>1</li> <li>2</li> <li>3</li> <li>4</li></ul>
(3) Get all li content programs with class dicTap
window.onload = function(){ var topMenus = getClass('li','dicTap'); for(var i=0;i < topMenus.length; i++) { alert(topMenus[i].innerHTML); }}(4) Actual application in the project
//Click the custom attribute personid, open the details page and pass the value across the page var dicTap = getClass('li','dicTap'); for(var i=0;i <dicTap.length; i++) { dicTap[i].addEventListener('tap',function(){ var personId=this.getAttribute("personid"); localStorage.a=personId; mui.openWindow({ url: 'disciplineDetail.html', id:'disciplineDetail' }); }) } //Encapsulate getClass function getClass(tagName,className) //Get the element with the tag name tagName and class name className { if(document.getElementsByClassName) //Support this function { return document.getElementsByClassName(className); } else { var tags=document.getElementsByTagName(tagName);//Get the tag var tagArr=[];//Use to return the element with the class name className for(var i=0;i < tags.length; i++) { if(tags[i].class == className) { tagArr[tagArr.length] = tags[i];//Save the element that meets the conditions} } return tagArr; } }The simple implementation of obtaining class in the above javascript is all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.