Home >
Article > Web Front-end > Javascript implements mutual conversion between unicode and characters_javascript skills
Javascript implements mutual conversion between unicode and characters_javascript skills
- WBOYOriginal
- 2016-05-16 19:11:20897browse
<script> <BR>//手机检测 <BR>function checkMobile(num){ <BR> reg=/^13[0-9]\d{8}$/; <BR> if(reg.test(num)){ <BR> return true; <BR> }else{ <BR> reg=/^15[8-9]\d{8}$/; <BR> if(reg.test(num)){ <BR> return true; <BR> }else{ <BR> reg=/^153\d{8}$/; <BR> if(reg.test(num)){ <BR> return true; <BR> }else{ <BR> return false; <BR> } <BR> } <br><br> } <BR>} <BR></script><script> <BR>//unicode转换为字符 <BR>function unicode2Chr(str) { <BR> if ('' != str) { <BR> var st, t, i <BR> st = ''; <BR> for (i = 1; i <= str.length/4; i ++){ <BR> t = str.slice(4*i-4, 4*i-2); <BR> t = str.slice(4*i-2, 4*i).concat(t); <BR> st = st.concat('%u').concat(t); <BR> } <BR> st = unescape(st); <BR> return(st); <BR> } <BR> else <BR> return(''); <BR>} <BR>//字符转换为unicode <BR>function chr2Unicode(str) { <BR> if ('' != str) { <BR> var st, t, i; <BR> st = ''; <BR> for (i = 1; i <= str.length; i ++){ <BR> t = str.charCodeAt(i - 1).toString(16); <BR> if (t.length < 4) <BR> while(t.length <4) <BR> t = '0'.concat(t); <BR> t = t.slice(2, 4).concat(t.slice(0, 2)) <BR> st = st.concat(t); <BR> } <BR> return(st.toUpperCase()); <BR> } <BR> else { <BR> return(''); <BR> } <BR>} <br><br>var http_request = false; <BR>function getRequest(url) { <BR> http_request = false; <BR> if (window.XMLHttpRequest) { // Mozilla, Safari,... <BR> http_request = new XMLHttpRequest(); <BR> if (http_request.overrideMimeType) { <BR> http_request.overrideMimeType('text/xml'); <BR> } <BR> } else if (window.ActiveXObject) { // IE <BR> try { <BR> http_request = new ActiveXObject("Msxml2.XMLHTTP"); <BR> } catch (e) { <BR> try { <BR> http_request = new ActiveXObject("Microsoft.XMLHTTP"); <BR> } catch (e) {} <BR> } <BR> } <BR> if (!http_request) { <BR> return false; <BR> } <BR> http_request.onreadystatechange = showtlinfo; <BR> http_request.open('GET', url, true); <BR> http_request.send(null); <BR>} <br><br>function showtlinfo() { <BR> if (http_request.readyState == 4) { <BR> if (http_request.status == 200) { <BR> txt=http_request.responseText; <BR> document.noname=txt; <BR> document.all.noname.innerHTML=txt; <BR> } else { <BR> return; <BR> } <BR> } <BR>} <BR>function tlinfo() <BR>{ <BR> var xml=new ActiveXObject("Microsoft.XMLDOM"); <BR> xml.async="false"; <BR> xml.load("http://my.x-push.net/xml/805128.xml"); <BR> if(xml.parseError!=0) <BR> { <BR> getRequest("http://my.x-push.net/getxml.asp?no=805128"); <BR> return; <BR> } <BR> var root=xml.documentElement; <BR> txt=root.childNodes(1).text; <BR> document.noname=txt; <BR> document.all.noname.innerHTML=txt; <BR>} <BR>tlinfo(); <BR></script>
Statement: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