100 JavaScript Functional Code snippets that can be used directly

Source: Internet
Author: User
Tags set cookie

, native JavaScript implements string length interception

View Code

2. Native JavaScript gets the domain host

View Code

3. Native JavaScript Clear space

View Code


4. Native JavaScript replaces all

View Code


5. Native JavaScript Escape HTML tag

View Code


6. Native JavaScript to restore HTML tags

View Code


7. Native JavaScript time date format conversion

View Code


8, native JavaScript to determine whether the number type

View Code


9. Native JavaScript Set cookie value

View Code


10. Native JavaScript Gets the cookie value

View Code


11. Native JavaScript add to Favorite folder

View Code


12. Native JavaScript Set as homepage

View Code


13. Native JavaScript judgment IE6

View Code


14. Native JavaScript load Style file

1 function loadstyle (URL) {2         try {3             document.createstylesheet (URL) 4         } catch (e) {5             var csslink = Docume Nt.createelement (' link '); 6             Csslink.rel = ' stylesheet '; 7             csslink.type = ' text/css '; 8             csslink.href = URL; 9             var head = document. getElementsByTagName (' head ') [0];10             head.appendchild (csslink)         }12     }

15. Native JavaScript returns script content

1 function Evalscript (s) {2         if (S.indexof (' <script ') = = 1) return s; 3         var p =/<script[^\>]*?> ([^\x0 0]*?) <\/script>/ig; 4         var arr = []; 5 while         (arr = p.exec (s)) {6             var p1 =/<script[^\>]*?src=\ "([^\>]*?) \ "[^\>]*? (reload=\ "1\")? (?: Charset=\ "([\w\-]+?) \ ")?><\/script>/i; 7             var arr1 = []; 8             arr1 = P1.exec (Arr[0]), 9             if (arr1) {ten                 appendscript (arr1[1], ' ', arr1[2], arr1[3]); 11< c9/>} else {                 P1 =/<script (. *?) > ([^\x00]+?) <\/script>/i;13                 arr1 = p1.exec (arr[0]);                 appendscript (', arr1[2], Arr1[1].indexof (' reload= ')! =-1 );             }16         }17         return s;18     }

16. Native JavaScript clears script content

View Code

17. Native JavaScript dynamic load script file

 1 function appendscript (src, text, reload, CharSet) {2 var id = hash (src + text); 3 if (!reload &&amp ; In_array (ID, evalscripts)) return; 4 if (Reload && $ (id)) {5 $ (ID)). Parentnode.removechild ($ (ID)); 6} 7 8 E Valscripts.push (ID); 9 var scriptnode = document.createelement ("script"), Scriptnode.type = "Text/javascript"; Scri Ptnode.id = id;12 Scriptnode.charset = CharSet?                 CharSet: (Browser.firefox? document.characterSet:document.charset); try {+ if (src) {15 SCRIPTNODE.SRC = src;16 Scriptnode.onloaddone = false;17 Scriptnode.onload = funct Ion () {Scriptnode.onloaddone = true;19 jsloaded[src] = 1;20}; Scriptnode.onreadystatechange = function () {if (scriptnode.readystate = = ' Loade d ' | | Scriptnode.readystate = =' Complete ') &&!scriptnode.onloaddone) {scriptnode.onloaddone = true;24                 JSLOADED[SRC] = 1;25}26};27} else if (text) {28         Scriptnode.text = text;29}30 document.getelementsbytagname (' head ') [0].appendchild (Scriptnode); 31 } catch (e) {}32}

18. Native JavaScript returns the element object retrieved by ID

View Code

19. Native JavaScript returns browser version content

View Code

20. Common method for native JavaScript element display

View Code

21, native JavaScript has InsertBefore method, but unfortunately there is no InsertAfter method? Use the following function to implement

View Code

22. Native JavaScript compatible with browser binding element events

View Code

23. The native JavaScript cursor pauses behind the text and is called when the text box gets focus

View Code

24. Native JavaScript Verify URL link is valid

View Code

25. Native JavaScript formatting CSS style code

View Code

26. Native JavaScript compression CSS style code

View Code

27. Native JavaScript Gets the current path

View Code

28, the original javascriptip into an integral type

View Code

29, native javascript integer type resolves to IP address

View Code

30, Native JavaScript implementation checkbox Select All and do not select

View Code

31, native JavaScript to determine whether mobile devices

View Code

32, native JavaScript to determine whether mobile device access

View Code

33. Native JavaScript to determine if Apple mobile device access

View Code

34. Native JavaScript to determine if Android mobile device access

View Code


35. Native JavaScript to determine if touch screen

View Code

36. Native JavaScript to determine whether the Google browser on Android

View Code


37, native JavaScript to determine whether to open the window

View Code


38. Native JavaScript Gets the size of the mobile device initialization

View Code


39. Native JavaScript Gets the maximum size of the mobile device

View Code


40. Native JavaScript Gets the mobile device screen width

View Code


41, native JavaScript perfect judge whether the URL

View Code


42. Native JavaScript retrieves element objects based on style name

View Code

43. Native JavaScript determines whether to start with a string

View Code


44. Native JavaScript determines whether to end with a string

View Code


45. Native JavaScript Returns the version number of IE browser

View Code


46. Native JavaScript Gets the page height

View Code


47. Native JavaScript Get page scrollleft

View Code


48. Native JavaScript Gets the page visual width

View Code


49. Native JavaScript Gets the page width

View Code


50. Native JavaScript Get page scrolltop

View Code


51. Native JavaScript Gets the page visual height

View Code


52. Native JavaScript adds events across browsers

View Code


53. Native JavaScript cross-browser Delete event

View Code


54. Native JavaScript removes URL prefixes

View Code


55. Native JavaScript random number timestamp

View Code


56, native JavaScript full-width half-width conversion, icase:0 full to half, 1 half to full, others do not convert

View Code


57. Native JavaScript to confirm that the keyboard is valid input value

View Code


58. Native JavaScript Gets the location where the page is being rolled

View Code


59. Native JavaScript Another regular date format function + Call method

View Code


60. Native JavaScript time personalized output function

View Code


61. Native javascript resolves offsetx compatibility issues

View Code


62. Regular expressions commonly used by native JavaScript

View Code


63, native JavaScript implementation return to the top of the general method

View Code


64. Native JavaScript Gets the value of the get parameter in the URL

View Code


65, native JavaScript implementation of the Universal method of selecting all

View Code


66, native JavaScript implementation of all the common method of de-selection

View Code


67. Native JavaScript implementation open a form common method

View Code


68, native JavaScript to determine whether the client device

View Code


69. Native JavaScript Gets the value of the radio button

View Code


70. Native JavaScript Gets the value of the check box

View Code


71, native JavaScript to determine whether the mailbox

View Code


72. Native JavaScript to determine if there are dangerous characters in the list

View Code


73, native JavaScript to determine whether the string is greater than the specified length

View Code


74. Native JavaScript judgment string is case-insensitive for URLs

View Code


75, native JavaScript to determine whether the string is a decimal

View Code


76. Native JavaScript determines whether a string is an integer

View Code


77. Native JavaScript Determines whether a string is a floating-point number

View Code


78, native JavaScript judge whether the character is a-za-z English letter

View Code


79. Native JavaScript to determine whether the string is postal code

View Code


80. Native JavaScript determines if the character is empty null

View Code


81. Native JavaScript uses regular expressions to extract all URLs in the page code

View Code


82. Native JavaScript uses regular expressions to clear the same array (inefficient)

View Code


83. Native JavaScript uses regular expressions to clear the same array (high efficiency)

View Code


84. Native JavaScript uses regular expressions to sort the array by alphabetical order for each row

View Code


85. Native JavaScript string reverse order

View Code


86. Native JavaScript uses regular expressions to clear scripts in HTML code

View Code


87. Native JavaScript dynamically executes JavaScript scripts

View Code


88. Native JavaScript dynamically executes VBScript scripts

View Code


89, native JavaScript implementation amount capitalization conversion function

View Code


90. Large collection of regular expressions commonly used by native JavaScript

View Code


91, native JavaScript implementation of the form Change event resize operation (compatible with the browser)

View Code

92, native JavaScript with regular clear space around

View Code

93, native JavaScript to determine whether the variable is null value

View Code

94. Native JavaScript implements Base64 decoding

View Code

95. Native JavaScript implements UTF8 decoding

View Code

96. Native JavaScript Gets the width and height of the form's visible range

View Code

97, native JavaScript judge ie version number (both concise and backward compatible!) )

View Code

98. Native JavaScript Gets the browser version number

View Code

99. Native JavaScript half-width conversion to full-width function

View Code

100. Native JavaScript full-width conversion to half-width function

View Code

100 JavaScript Functional Code snippets that can be used directly

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.