私信  •  关注

Phil

Phil 最近回复了
2 年前
回复了 Phil 创建的主题 » 使用Jquery附加到所有href和src属性

使用jQuery的 attr() 使用回调函数来追加值。

例如

const suffix = "/Demo_App";

// all elements with `src` attribute
$("[src]").attr("src", (_, src) => src + suffix)

// all elements with `href` attribute
$("[href]").attr("href", (_, href) => href + suffix)

一如既往 you might not need jQuery

const suffix = "/Demo_App";

document.querySelectorAll("[src]").forEach(elt => {
  elt.src += suffix
})

document.querySelectorAll("[href]").forEach(elt => {
  elt.href += suffix
})