如何转换此jquery代码
$(element).find('.ui.dropdown') 到纯JS?
我需要将JQUERY中的简单代码转换为纯JS。
在我的代码中,element是一个变量,它来自下面的代码:
$.each($("[action]").toArray(), function(key, element)发布于 2020-05-11 23:07:25
下面的内容如何?
Array.prototype.slice.call(document.querySelectorAll('[action]')).forEach(function (element, index) {
element.querySelector('.ui.dropdown')
// do something to the element
});如前所述,只有当您运行的浏览器不支持NodeList.prototype.forEach()时,才需要Array.prototype.slice()。对于现代浏览器,您实际上可以这样做:
document.querySelectorAll('[action]').forEach(function (element, index) {
element.querySelector('.ui.dropdown')
// do something to the element
});https://stackoverflow.com/questions/61732891
复制相似问题