Links

getAttr

说明

获取DOM的特定属性值

源码

用法

getAttr.test.ts
import { getAttr } from "../../utility/dom/getAttr";
describe('getAttr', () => {
test('getAttr should return null when nothing matched ', () => {
document.body.innerHTML += `
<input type="text" id="text" class="text" />
`;
expect(
getAttr((document.getElementById('text') as HTMLElement), 'disabled')
).toBeNull();
});
test('getAttr should return the value when matched', () => {
document.body.innerHTML = `
<input type="text" id="text" class="text" />
`;
expect(getAttr(
(document.getElementById('text') as HTMLElement),
'type',
)).toBe('text');
});
});
最近更新 3yr ago