为什么 str.replace 不想更改此 <> 符号?
Why doesn't str.replace want to change this <> symbol?
我需要将 > 更改为 %3E ..,如果 > 符号被另一个符号更改,一切正常。
我该如何纠正?
<p id="demo">this > and this > symbol should be replaced.</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
var str = document.getElementById("demo").innerHTML;
var res = str.replace(/>/g, "%3E");
document.getElementById("demo").innerHTML = res;
}
您必须在 Regex 中找到 >
(大于)并替换为 <
。
<p id="demo">this > and this > symbol should be replaced.</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
var str = document.getElementById("demo").innerHTML;
var res = str.replace(/\>\;/g, "\%3E");
document.getElementById("demo").innerHTML = res;
}
</script>
我需要将 > 更改为 %3E ..,如果 > 符号被另一个符号更改,一切正常。 我该如何纠正?
<p id="demo">this > and this > symbol should be replaced.</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
var str = document.getElementById("demo").innerHTML;
var res = str.replace(/>/g, "%3E");
document.getElementById("demo").innerHTML = res;
}
您必须在 Regex 中找到 >
(大于)并替换为 <
。
<p id="demo">this > and this > symbol should be replaced.</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
var str = document.getElementById("demo").innerHTML;
var res = str.replace(/\>\;/g, "\%3E");
document.getElementById("demo").innerHTML = res;
}
</script>