StylePropertyMapReadOnly: phương thức has()
Khả dụng hạn chế
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Phương thức has() của giao diện StylePropertyMapReadOnly cho biết liệu thuộc tính được chỉ định có tồn tại trong đối tượng StylePropertyMapReadOnly hay không.
Cú pháp
js
has(property)
Tham số
property-
Tên của thuộc tính cần kiểm tra.
Giá trị trả về
Một giá trị boolean.
Ví dụ
Ví dụ này dùng phương thức has() để kiểm tra xem thuộc tính padding-top có trong thuộc tính style của phần tử button hay không.
js
// get the button element
const buttonEl = document.querySelector(".example");
// find what's in the style attribute with attributeStyleMap and has()
const hasPadTop = buttonEl.attributeStyleMap.has("padding-top");
console.log(hasPadTop); // logs true if padding-top is present in style attribute
Thông số kỹ thuật
| Thông số kỹ thuật |
|---|
| CSS Typed OM Level 1> # dom-stylepropertymapreadonly-has> |