HTML DOMTokenList forEach()
❮ Đối tượng DOMTokenListVí dụ
Nhận DOMTokenList từ "bản demo":
let list = document.getElementById("demo").classList;
Hãy tự mình thử »Thực thi một chức năng cho mỗi mã thông báo:
list.forEach(
function(token, index) {
text += index + " " + token;
}
);
Hãy tự mình thử »Sự miêu tả
Phương thức forEach()
thực thi chức năng gọi lại cho từng mã thông báo trong DOMTokenList .
Xem thêm:
Cú pháp
nodelist .forEach( function(currentValue, index, arr), thisValue )
Thông số
function() | Required. A function to run for each token. |
currentValue | Required. The value of the current token. |
index | Optional. The index of the current token. |
arr | Optional. The DOMTokenList of the current token. |
thisValue | Optional. Default undefined .A value passed to the function as its this value. |
Giá trị trả về
KHÔNG CÓ |
Hỗ trợ trình duyệt
domtokenlist.forEach()
là tính năng DOM cấp 4 (2015).
Nó được hỗ trợ trong tất cả các trình duyệt hiện đại:
Chrome | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes |
domtokenlist.forEach()
không được hỗ trợ trong Internet Explorer 11 (hoặc phiên bản cũ hơn).
❮ Đối tượng DOMTokenList