-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextendLikeJQuery.js
86 lines (55 loc) · 1.45 KB
/
extendLikeJQuery.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/**
* 此方法用于扩展 likeJQuery.js
* 添加常用的方法
* 需要先引入<script src="likeJQuery.js"></script>
*
*
*/
(function (win, doc, $) {
function _detect(ua) {
var os = this.os = {},
android = ua.match(/(Android);?[\s\/]+([\d.]+)?/);
if (android) {
os.android = true;
os.version = android[2];
}
}
_detect.call($, navigator.userAgent);
/**
* 只能是一个 HTMLElement不支持字符串
* @param {Element} $child
* @param {Boolean} flag true:要复制节点
* @returns {append}
*/
function append($child, flag) {
var clone;
// 只能是元素对象
if (!($child instanceof HTMLElement)) return this;
this.forEach(function ($element) {
if (flag) clone = $child.cloneNode(true);
$element.appendChild(clone || $child);
});
return this;
}
/**
* 移除当前元素
* @returns {remove}
*/
function remove() {
this.forEach(function ($element) {
$element.parentNode.removeChild($element);
});
return this;
}
/**
* 找出当前元素的孩子节点
* @param selector
* @returns {HTMLElement}
*/
function find(selector) {
return $(selector, this);
}
$.fn.append = append;
$.fn.remove = remove;
$.fn.remove = find;
})(window, document, $);