【发布时间】:2021-02-25 12:51:26
【问题描述】:
我有一些<a href="javascript:; 形式的链接,我需要在其中找到http 并将其替换为https://
简单地编写一个 JS 代码来查找http 在这种情况下不起作用,我完全被卡住了。
在 <a href="javascript:some very long lines;">Link</a> 这样的表达式中找到链接的最佳方法是什么?
window.onload = function() {
let url = document.querySelectorAll('.page-numbers');
url.forEach((e) => {
e.setAttribute('href', e.href.replace(/^http:\/\//i, 'https://'));
console.log(e);
});
};
<div class="pagingSection">
<a href="javascript:WebF(new WebFform("ctl01$ctl8$g_8f9c2af0", "", false, "", "http://www.example.com/test.aspx?cor=%20;403-7e1ee457616b%7%20;0374d4027-5a27-4421-9771-6326d4746a20%7%20ol;&areaId=%=6", false, true))" class="page-numbers">Link 1</a>
<a href="javascript:WebF(new WebFform("ctl01$ctl8$g_8f9c2af0", "", false, "", "http://www.example.com/test2.aspx?cor=%20;403-7e1ee457616b%7%20;0374d4027-5a27-4421-9771-6326d4746a20%7%20ol;&areaId=%=7", false, true))" class="page-numbers">Link 2</a>
<a href="javascript:WebF(new WebFform("ctl01$ctl8$g_8f9c2af0", "", false, "", "http://www.example.com/test3.aspx?cor=%20;403-7e1ee457616b%7%20;0374d4027-5a27-4421-9771-6326d4746a20%7%20ol;&areaId=%=8", false, true))" class="page-numbers">Link 3</a>
</div>
【问题讨论】:
标签: javascript html regex replace hyperlink