0
我有这个代码获取查询字符串值并将其显示在h3
中。我试图将URL中的任何%20
更改为空格。我试过使用.replace
,但它不起作用。用html替换文本?
<h3 style="text-decoration: underline;margin-left:10px;color:white;position: absolute;
z-index: 999;">
<script>
function frtitlen(frtitle) {
frtitle = frtitle.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + frtitle + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.href);
if (results == null) return "Untitled";
else {
return results[1];
}
}
</script>
<script>
document.write(frtitlen('frtitle'));
</script>
</h3>
使用decodeURIComponent来解码转义字符,比试图使用regexp更容易 –