Last active
August 29, 2015 14:04
-
-
Save findyourmagic/6a849b389777590e22cd to your computer and use it in GitHub Desktop.
javascript fragment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var arr = [1,2,3,[1,2,3]]; | |
| var objToString = Object.prototype.toString; | |
| function getType( obj ){ | |
| var str = objToString.call(obj); | |
| str = str.split(' ')[1]; | |
| str = str.slice(0,str.length - 1); | |
| return str.toLowerCase(); | |
| } | |
| function copyObj( obj){ | |
| if ( getType(obj) == 'array' ){ | |
| var newObj = []; | |
| }else if ( getType(obj) == 'object') { | |
| var newObj = {}; | |
| }else{ | |
| return obj; | |
| }; | |
| for ( var i in obj){ | |
| (function(){ | |
| var item = obj[i]; | |
| if ( getType(item) == 'array' || getType(item) == 'object' ){ | |
| newObj[i] = copyObj(item); | |
| }else{ | |
| newObj[i] = item; | |
| } | |
| })(); | |
| } | |
| return newObj; | |
| } | |
| var arr1 = copyObj(arr); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var getSearch = function(){ | |
| var search = window.location.search; | |
| var reg = /([^\=\?\&]+)\=([^\=\?\&]+)/g; | |
| var obj = {}; | |
| search.replace(reg , function( item, key, value){ | |
| obj[key] = decodeURIComponent(value); | |
| return item; | |
| }); | |
| return obj; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function keyUp(e) { | |
| var currKey=0,e=e||event; | |
| var currKey=e.keyCode||e.which||e.charCode; | |
| var keyName = String.fromCharCode(currKey); | |
| alert("按键码: " + currKey + " 字符: " + keyName); | |
| } | |
| document.onkeyup = keyUp; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment