js好用代码(217)

js(判断俩对象属性是否相同)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
function IsPropertyEqual(obj1, obj2) {
if (obj1 === obj2) {
return true;
}
if (!(obj1 instanceof Object) || !(obj2 instanceof Object)) {
return false;
}
for (var p in obj1) {
if (obj1.hasOwnProperty(p) && !obj2.hasOwnProperty(p)) {
return false;
}
}
for (p in obj2) {
if (obj1.hasOwnProperty(p) && !obj2.hasOwnProperty(p)) {
return false;
}
}
return true;
}
function IsStructer(data, obj) {
return IsPropertyEqual(obj, JSON.parse(data));
}

angular(文件选取)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<input type="file" fileread="app.js" />
.directive("fileread", [function () {
return {
scope: {
fileread: "="
},
link: function (scope, element, attributes) {
element.bind("change", function (changeEvent) {
scope.$apply(function () {
scope.fileread = changeEvent.target.files[0];
});
var reader = new FileReader();
reader.onload = function (etc) {
etc.target.result;
//reader.readAsText(scope.fileread);
});
}
}
}]);

文件下载(超好用,本地下载类型的)

http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js

// //