This file contains 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
//slice和substring接收的是起始位置和结束位置(不包括结束位置),而substr接收的则是起始位置和所要返回的字符串长度 | |
var test = 'hello world'; | |
test.slice(4, 7); //o w | |
test.substring(4, 7); //o w | |
test.substr(4, 7); //o world | |
//slice、substr使用负数作为参数表示从字符串尾部开始截取,substring则将负参数都直接转换为0 | |
test.slice(-3); //rld | |
test.substring(-3); //hello world | |
test.substr(-3); //rld |
This file contains 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 typeOf(obj) { | |
var _toString = Object.prototype.toString; | |
var _type ={ | |
"undefined" : "undefined", | |
"number" : "number", | |
"boolean" : "boolean", | |
"string" : "string", | |
"[object Function]" : "function", | |
"[object RegExp]" : "regexp", | |
"[object Array]" : "array", |
This file contains 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
// From : http://www.quirksmode.org/js/detect.html | |
var BrowserDetect = { | |
init: function() { | |
this.browser = this.searchString(this.dataBrowser) || "An unknown browser"; | |
//navigator.userAgent may not contain the string "iCab", but navigator.appVersion always does. | |
this.version = this.searchVersion(navigator.userAgent) || this.searchVersion(navigator.appVersion) || "an unknown version"; | |
this.OS = this.searchString(this.dataOS) || "an unknown OS"; | |
}, | |
searchString: function(data) { | |
for (var i = 0; i < data.length; i++) { |
This file contains 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
if (document.selection) { | |
//IE | |
alert(document.selection.createRange().text); | |
} | |
else if (window.getSelection()) { | |
//Firefox, Chrome ... | |
alert(window.getSelection()); | |
} |
This file contains 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
//Note From: Professional JavaScript for Web Developers | |
var sUserAgent = navigator.userAgent; | |
var fAppVersion = parseFloat(navigator.appVersion); | |
function compareVersions(sVersion1, sVersion2) { | |
var aVersion1 = sVersion1.split("."); | |
var aVersion2 = sVersion2.split("."); | |
if (aVersion1.length > aVersion2.length) { | |
for (var i=0; i < aVersion1.length - aVersion2.length; i++) { |
This file contains 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, 4, 5]; | |
//从第二个下标,删除0个元素,并插入一个6,无返回值 | |
arr.splice(2, 0, 6); | |
//从第二个下标,删除1个元素(3),并插入一个'6'--等同于替换index=3的元素,返回被删除的元素集合([3]),arr->[1, 2, 6, 4, 5] | |
arr.splice(2, 1, 6); | |
//从第二个下标,删除2个元素(3,4),并插入一个6,返回被删除的元素集合([3,4]),arr->[1, 2, 6, 5] | |
arr.splice(2, 2, 6); |
This file contains 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
/*iPhone5*/ | |
@media screen and (device-aspect-ratio: 40/71) {} | |
/*或者: | |
@media screen and (device-width: 320px) and (device-height: 568px) and (-webkit-device-pixel-ratio: 2){} | |
/*iPhone 5 In Portrait & Landscape*/ | |
@media only screen | |
and (min-device-width : 320px) | |
and (max-device-width : 568px){ | |
} |
This file contains 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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> | |
<html lang="en"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> | |
<title>Test</title> | |
<style type="text/css"> | |
</style> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> | |
</head> |
This file contains 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
Assembly asm = Assembly.GetExecutingAssembly(); | |
var names = (from n in asm.GetManifestResourceNames() | |
where n.EndsWith(".png") | |
select n | |
).ToList(); | |
Dictionary<string, System.IO.Stream> resources = new Dictionary<string, System.IO.Stream>(); | |
foreach (string name in names) | |
{ |
This file contains 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 client = new WebClient(); | |
client.OpenReadCompleted += (s, ex) => | |
{ | |
var info = new StreamResourceInfo(ex.Result, null); | |
var bitmapInfo = Application.GetResourceStream(info, new Uri("1.png", UriKind.RelativeOrAbsolute)); | |
var bitmap = new BitmapImage(); | |
bitmap.SetSource(bitmapInfo.Stream); |
OlderNewer