JS convert URL to urlencode type _javascript tips

Source: Internet
Author: User
Tags urlencode
Call the method, write the following function in a JS file that supports calling
The website to be encode will be changed
<textarea id="runcode2093"><script> function UrlEncode (str) {return transform (str); Function transform (s) {var hex= ' var i,j,t j=0 for (i=0; i<s.length; i++) {t = Hexfromdec (s). charCodeAt (i)); if (t== ') {t= '; } hex + = '% ' + t; return hex; } function Hexfromdec (num) {if (num > 65535) {return ("err!")} A-Math.Round (num/4096-. 5); Temp1 = Num-first * 4096; Second = Math.Round (temp1/256-.5); TEMP2 = Temp1-second * 256; Third = Math.Round (TEMP2/16-. 5); Fourth = Temp2-third * 16; Return ("" +getletter (third) +getletter (fourth)); } function Getletter (num) {if (num <) {return num; else {if (num = =] {return "A"} if (num = =) {return "B"} if (num =) {return "C"} if (num =) {R Eturn "D"} if (num = = return "E"} if (num =) {return ' F '}}} alert (UrlEncode ("Programming")); </script></textarea>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.