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更容易 –