社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
私信  •  关注

Phil

Phil 最近回复了
3 年前
回复了 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
})