getAttr

说明

获取DOM的特定属性值

源码

用法

getAttr.test.ts
1
import { getAttr } from "../../utility/dom/getAttr";
2
3
describe('getAttr', () => {
4
test('getAttr should return null when nothing matched ', () => {
5
document.body.innerHTML += `
6
<input type="text" id="text" class="text" />
7
`;
8
9
expect(
10
getAttr((document.getElementById('text') as HTMLElement), 'disabled')
11
).toBeNull();
12
});
13
14
test('getAttr should return the value when matched', () => {
15
document.body.innerHTML = `
16
<input type="text" id="text" class="text" />
17
`;
18
19
expect(getAttr(
20
(document.getElementById('text') as HTMLElement),
21
'type',
22
)).toBe('text');
23
});
24
});
Copied!
最近更新 1yr ago
复制链接