@whitesev/domutils 1.3.3 → 1.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.amd.js +2 -2
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +2 -2
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +2 -2
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +2 -2
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +2 -2
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +2 -2
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/DOMUtils.d.ts +4 -5
- package/package.json +1 -1
- package/src/DOMUtils.ts +9 -10
|
@@ -26,7 +26,7 @@ declare class DOMUtils extends DOMUtilsEvent {
|
|
|
26
26
|
* DOMUtils.attr(document.querySelector("a.xx"),"href","abcd");
|
|
27
27
|
* DOMUtils.attr("a.xx","href","abcd");
|
|
28
28
|
*/
|
|
29
|
-
attr(element: HTMLElement | string, attrName: string, attrValue: string): void;
|
|
29
|
+
attr(element: HTMLElement | string, attrName: string, attrValue: string | boolean | number): void;
|
|
30
30
|
/**
|
|
31
31
|
* 创建元素
|
|
32
32
|
* @param tagName 标签名
|
|
@@ -115,9 +115,8 @@ declare class DOMUtils extends DOMUtilsEvent {
|
|
|
115
115
|
[key: string]: string | number;
|
|
116
116
|
}): string;
|
|
117
117
|
/**
|
|
118
|
-
*
|
|
118
|
+
* 获取元素的文本内容,优先返回textContent
|
|
119
119
|
* @param element 目标元素
|
|
120
|
-
* @param text (可选)文本内容
|
|
121
120
|
* @returns 如果传入了text,则返回undefined;否则返回文本内容
|
|
122
121
|
* @example
|
|
123
122
|
* // 设置元素a.xx的文本内容为abcd
|
|
@@ -137,7 +136,7 @@ declare class DOMUtils extends DOMUtilsEvent {
|
|
|
137
136
|
* DOMUtils.text("a.xx","abcd")
|
|
138
137
|
* DOMUtils.text("a.xx",document.querySelector("b"))
|
|
139
138
|
* */
|
|
140
|
-
text(element: HTMLElement | string, text: string | HTMLElement | Element): void;
|
|
139
|
+
text(element: HTMLElement | string, text: string | HTMLElement | Element | number): void;
|
|
141
140
|
/**
|
|
142
141
|
* 设置元素的HTML内容
|
|
143
142
|
* @param element 目标元素
|
|
@@ -149,7 +148,7 @@ declare class DOMUtils extends DOMUtilsEvent {
|
|
|
149
148
|
* DOMUtils.html("a.xx","<b>abcd</b>")
|
|
150
149
|
* DOMUtils.html("a.xx",document.querySelector("b"))
|
|
151
150
|
* */
|
|
152
|
-
html(element: HTMLElement | string, html: string | HTMLElement | Element): void;
|
|
151
|
+
html(element: HTMLElement | string, html: string | HTMLElement | Element | number): void;
|
|
153
152
|
/**
|
|
154
153
|
* 获取元素的HTML内容
|
|
155
154
|
* @param element 目标元素
|
package/package.json
CHANGED
package/src/DOMUtils.ts
CHANGED
|
@@ -11,7 +11,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
11
11
|
super(option);
|
|
12
12
|
}
|
|
13
13
|
/** 版本号 */
|
|
14
|
-
version = "2024.
|
|
14
|
+
version = "2024.10.19";
|
|
15
15
|
/**
|
|
16
16
|
* 获取元素的属性值
|
|
17
17
|
* @param element 目标元素
|
|
@@ -36,9 +36,9 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
36
36
|
attr(
|
|
37
37
|
element: HTMLElement | string,
|
|
38
38
|
attrName: string,
|
|
39
|
-
attrValue: string
|
|
39
|
+
attrValue: string | boolean | number
|
|
40
40
|
): void;
|
|
41
|
-
attr(element: HTMLElement | string, attrName: string, attrValue?:
|
|
41
|
+
attr(element: HTMLElement | string, attrName: string, attrValue?: any) {
|
|
42
42
|
let DOMUtilsContext = this;
|
|
43
43
|
if (typeof element === "string") {
|
|
44
44
|
element = DOMUtilsContext.windowApi.document.querySelector(
|
|
@@ -263,9 +263,8 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
263
263
|
}
|
|
264
264
|
}
|
|
265
265
|
/**
|
|
266
|
-
*
|
|
266
|
+
* 获取元素的文本内容,优先返回textContent
|
|
267
267
|
* @param element 目标元素
|
|
268
|
-
* @param text (可选)文本内容
|
|
269
268
|
* @returns 如果传入了text,则返回undefined;否则返回文本内容
|
|
270
269
|
* @example
|
|
271
270
|
* // 设置元素a.xx的文本内容为abcd
|
|
@@ -287,9 +286,9 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
287
286
|
* */
|
|
288
287
|
text(
|
|
289
288
|
element: HTMLElement | string,
|
|
290
|
-
text: string | HTMLElement | Element
|
|
289
|
+
text: string | HTMLElement | Element | number
|
|
291
290
|
): void;
|
|
292
|
-
text(element: HTMLElement | string, text?:
|
|
291
|
+
text(element: HTMLElement | string, text?: any) {
|
|
293
292
|
let DOMUtilsContext = this;
|
|
294
293
|
if (typeof element === "string") {
|
|
295
294
|
element = DOMUtilsContext.windowApi.document.querySelector(
|
|
@@ -326,7 +325,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
326
325
|
* */
|
|
327
326
|
html(
|
|
328
327
|
element: HTMLElement | string,
|
|
329
|
-
html: string | HTMLElement | Element
|
|
328
|
+
html: string | HTMLElement | Element | number
|
|
330
329
|
): void;
|
|
331
330
|
/**
|
|
332
331
|
* 获取元素的HTML内容
|
|
@@ -340,7 +339,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
340
339
|
* DOMUtils.html("a.xx",document.querySelector("b"))
|
|
341
340
|
* */
|
|
342
341
|
html(element: HTMLElement | string): string;
|
|
343
|
-
html(element: HTMLElement | string, html?:
|
|
342
|
+
html(element: HTMLElement | string, html?: any) {
|
|
344
343
|
let DOMUtilsContext = this;
|
|
345
344
|
if (typeof element === "string") {
|
|
346
345
|
element = DOMUtilsContext.windowApi.document.querySelector(
|
|
@@ -353,7 +352,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
353
352
|
if (html == null) {
|
|
354
353
|
return element.innerHTML;
|
|
355
354
|
} else {
|
|
356
|
-
if (html instanceof
|
|
355
|
+
if (html instanceof Element) {
|
|
357
356
|
html = html.innerHTML;
|
|
358
357
|
}
|
|
359
358
|
if ("innerHTML" in element) {
|