-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoperation.js
40 lines (35 loc) · 1.39 KB
/
operation.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
(function () {
var utils = {};
//attr:获取或者设置当前元素的自定义属性
utils.attr = function attr(curEle, attr, value) {
if (typeof value === "undefined") {
return attr === "class" ? curEle.className : curEle.getAttribute(attr);
}
attr === "class" ? curEle.className = value : curEle.setAttribute(attr, value);
};
//html:获取或者设置当前元素的内容
utils.html = function html(curEle, value) {
if (typeof value === "undefined") {
return curEle.innerHTML;
}
curEle.innerHTML = value;
};
//val:获取或者设置当前表单元素的value值
utils.val = function val(curEle, value) {
if (typeof value === "undefined") {
return curEle.value;
}
curEle.value = value;
};
//prepend:向指定容器的开头增加元素(依赖query.js)
utils.prepend = function prepend(container, newEle) {
var fir = this.first(container);
fir ? container.insertBefore(newEle, fir) : container.appendChild(newEle);
};
//insertAfter:向指定容器中某个元素之前增加新元素(依赖query.js)
utils.insertAfter = function insertAfter(oldEle, newEle) {
var nex = this.next(oldEle), par = oldEle.parentNode;
nex ? par.insertBefore(newEle, nex) : par.appendChild(newEle);
};
window.ztDOM.extend(utils);
})();