【发布时间】:2019-03-07 03:45:29
【问题描述】:
我正在尝试删除一个 jQuery 依赖项,并用循环替换这个 .each 证明很棘手。
// inline <img> when src = .svg so it is styled with CSS
$('[src$=".svg"]').each(function() { // get .svg
var $img = $(this);
var imgURL = $img.attr("src"); // get src url
$.get(
imgURL,
function(data) { // Get the SVG guts from image file
var $svg = $(data).find("svg");
$img.replaceWith($svg); // Replace img with SVG guts
}, "xml"
);
});
【问题讨论】:
-
您的问题是什么?您已经尝试过哪些不起作用的方法?
-
根据您的需要,您可以使用
map()或forEach()。但是替换.each()调用并不是唯一的 jQuery 依赖项。您还需要用其他东西实现匹配。 -
欢迎来到stackoverflow @AndyFitz,因此,您的问题很难理解,因为很难看到您在问什么。你能说一些更多的细节吗? (错误信息,是什么阻碍了你)
-
您能否澄清一下您所说的“证明棘手”是什么意思?
标签: javascript ecmascript-6 ecmascript-2016