Home >Web Front-end >JS Tutorial >JavaScript practical small functions (code examples)
The content this article brings to you is about JavaScript practical functions, which has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
My own modified method of getting class
// 获取class <script type="text/javascript"> function getByClass(oParent,sClass){ var aEle=oParent.getElementsByTagName("*"); var aResult=[]; for(var i=0,tt=aEle.length;i<tt;i++){ if(aele[i].classname.indexof(sclass)="">=0){ var arr_class=aEle[i].className.split(" "); for(var j=0,len=arr_class.length;j<len;j++){ if(arr_class[j]="=sClass){" aresult.push(aele[i]);="" }="" return="" aresult;="" <="" script>="" <="" pre=""></len;j++){></tt;i++){>
2. Get element style
// 获取样式 function getStyle(obj,name){ if(obj.currentStyle){ return obj.currentStyle[name]; } else{ return getComputedStyle(obj,false)[name]; } }
3. Prevent event bubbling
// 阻止事件冒泡 function stopBubble(e){ if(e && e.stopPropagation){ e.stopPropagation(); } else{ window.event.cancelBubble=true; } return false; }
4. Full screen mode
// 退出全屏 function exitFullScreen() { var el = document, cfs = el.cancelFullScreen || el.webkitCancelFullScreen || el.mozCancelFullScreen || el.exitFullScreen, wscript; if (typeof cfs != "undefined" && cfs) { cfs.call(el); return; } if (typeof window.ActiveXObject != "undefined") { wscript = new ActiveXObject("WScript.Shell"); if (wscript != null) { wscript.SendKeys("{F11}"); } } }
The above is the complete introduction to JavaScript’s practical functions. If you want to know more about JavaScript video tutorial, please pay attention to the PHP Chinese website .
The above is the detailed content of JavaScript practical small functions (code examples). For more information, please follow other related articles on the PHP Chinese website!