3 回答
TA贡献2037条经验 获得超6个赞
在这里回答我自己的问题。
这是我的工作代码/我最终做了什么(欢迎批评/改进想法),包括我自己添加的评论:
<script>
// Gets the URL of a link into the anchor text and removes extra characters.
// Notes:
// - This could most likely be done more elegantly since they are referencing the same element!
// - This was done in a WP/Elementor page with weird selectors.
var myanchor = document.querySelector(".partner-website-url.elementor-widget.elementor-widget-heading a");
var myurl = document.querySelector(".partner-website-url.elementor-widget.elementor-widget-heading a").href;
var cleanurl = myurl.replace(/http(s)://(www\.)/, '').replace(//+$/, '');
myanchor.innerHTML += cleanurl;
</script>
TA贡献2065条经验 获得超13个赞
在访问 DOM 之前等待页面加载
访问
NodeList
返回的第一个元素getElementsByTagName
清理网址并重新设置
document.onLoad = function () {
var ele = document.getElementById("partner-website-element").getElementsByTagName('a');
ele[0].innerHTML = ele[0].innerHTML.replace(/http(s):\/\/(www)/gi, '');
}
添加回答
举报