如何转义src url以插入自定义值?我的目标:
<script src="https://url.com?value=MY_ESCAPED_CUSTOM_VALUE"></script>
答案 0 :(得分:0)
试试这个:
var x=document.querySelector("[src^='https://url.com']");
var url=x.getAttribute('src');
var value=url.substring(url.lastIndexOf('='),url.length-1);
url=url.replace(value,YOUR_CUSTOM_VALUE);
x.setAttribute("src", url);
答案 1 :(得分:0)
var url="https://some.url?value=" + MY_ESCAPED_CUSTOM_VALUE;
<script src={url}></script>