为什么 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 中找到 &gt;(大于)并替换为 <

Read more here

<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(/\&gt\;/g, "\%3E");
  document.getElementById("demo").innerHTML = res;
}
</script>