Summarize some js custom functions_javascript skills
WBOY
Release: 2016-05-16 19:27:16
Original
916 people have browsed it
1. dayin() Function: Create a new page and print the content with the id of dayin, which can solve the problem of printing part of the content on a page. Usage: Include the content to be printed by , and then define the event
where code=code.replace(/] *>Delete/gi, ""); is to filter out all deleted connections in the content
2. isNumber(st) Function: Determine whether the variable st is It consists of numbers (including negative numbers and decimals). If it is, it returns true, otherwise it returns false. function isNumber(st) { var Letters = "1234567890-."; var i; var c; if(st.charAt( 0 )==' .') return false; if(st.charAt( 0 )=='-'&&st.charAt( 1 )=='.') return false; if( st. charAt( st.length - 1 ) == '-' ) return false; for( i = 0; i < st.length; i ) { c = st.charAt ( i ); if (Letters.indexOf( c ) < 0) return false; } return true; }
3. createCookie(name,value,days) Function: Create a cookie with name name, value value, and validity period of days. Can be modified at the same time. function createCookie(name,value,days){ var expires = ""; if (days) { var date = new Date(); date.setTime(date. getTime() (days*24*60*60*1000)); expires = "; expires=" date.toGMTString(); }; document.cookie = name "=" value expires "; path="/"; };
4. readCookie(name) Function: Read the value of the cookie based on the name. If none, returns null. function readCookie(name){ var nameEQ = name "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i ) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); }; return null; };
5. request(st) Function: Get the value of a certain parameter in the browser address bar (not a perfect solution, for example, if there are spaces, you will get it, but it supports Chinese) function request(st) { var ustr=document.location.search; var intPos = ustr.indexOf("?"); var strRight = ustr.substr(intPos 1); var arrTmp = strRight.split( "&"); for(var i = 0; i < arrTmp.length; i ) { var arrTemp = arrTmp[i].split("="); if (arrTemp[0].toUpperCase() == st.toUpperCase()) return arrTemp[1]; } return ""; }
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn