以下代码在本机JS中的外观如何?
$(".custom-popover").hide();
答案 0 :(得分:2)
这个问题有点广泛。 jQuery内部有这样的方式,然后有一种方法可以使用本机JavaScript来完成它,而不管jQuery如何做到这一点:
[].slice.call(
document.querySelectorAll('.custom-popover')).forEach(function (el) {
el.style.display = 'none';
}
);
由于document.querySelectorAll
返回nodelist
无法与forEach
一起使用的slice
,您可以通过调用nodelist
上的style
将其转换为实际数组。之后,遍历找到的所有内容并更新forEach
属性。
这是一个不使用var els = document.querySelectorAll('.custom-popover');
for (var i = 0; i < els.length; i++) {
els[i].style.display = 'none';
}
的替代,但我更喜欢上述方法:
(TF as ILinkable).BugLinkFactory;