【问题标题】:Javascript - Replace '%20' spacesJavascript - 替换“%20”空格
【发布时间】:2010-07-09 17:21:59
【问题描述】:
var loc_array = document.location.href.split('/');
var linkElement = document.getElementById("waBackButton");
var newT = document.createTextNode(loc_array[loc_array.length-2]); 
var repl = newT.replace('%20',' ');
linkElement.appendChild(repl);

有人知道为什么这会导致文本不显示吗?

【问题讨论】:

    标签: javascript dom replace


    【解决方案1】:

    为什么不干呢

    unescape(document.location.href);
    

    【讨论】:

    • 那会去哪里。我最后有 .split()。
    • 我会在拆分之前对字符串进行转义。理解如果你在 document.location.href 上使用 .split('\'),你会得到一些空元素。您的数组将类似于:['http:','','www.someplace.com','dir1','subdir1','afile.htm?foo=bar&spork=spoon+fork']
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-16
    • 1970-01-01
    • 2012-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多