I have been judging rhino books recently, and I have thoughts, so I wrote a simple dom query for JS
$ = function (val) { switch(val.charAt(0)) { case '#' : return document.getElementById(val.substring(1)); break; case '.' : val = val.replace('.',''); if(document.getElementsByClassName) return document.getElementsByClassName(val); else { var obj = document.getElementsByTagName('*'),len = obj.length,arr=[]; for(var i=0;i<len;i++) { if(obj[i].className == val) { arr[arr.length] = obj[i]; } } return arr; } break; default : if(document.getElementsByName(val).length > 0) return document.getElementsByName(val); else return document.getElementsByTagName(val); } }In this way, when calling id in the future, you only need $('#idname'), $('.classname'), TagName and Name both make simple judgments, both pass $('name'). I tried it and it felt OK.
The above simple encapsulated dom query example code of JS is all the content I share with you. I hope it can give you a reference and I hope you can support Wulin.com more.