JavaScript如何将%20替换为空格

Sha*_*eer 9 javascript urldecode angularjs

我正在尝试从URL中检索值并使用angular JS在我的网页中显示它.我在做什么

1)将整个url保存到变量并将其拆分,以便我可以过滤到我需要的值.

2)但是当有空格时,它显示为%20.我希望这个%20显示为空格本身.

示例:john doe显示为john%20doe

调节器

function InboxController($scope, $http, $cookieStore, $location) {
    $scope.single_mail = function()
      { 
        var url = $location.url();
        var split_url = url.split('=');
        var mess_id = split_url[1];
        var from =  split_url[2];
        var id_value = mess_id.split('&');
        var inbox_id = id_value[0];
        var from_value = from.split('&');
        $scope.inbox_from = from_value[0];
        $scope.single_message = [];
        $scope.single_message = [];
        var single_inbox_mail ="https://phoe.manage.com/app/inbox/message.html?contactid="+conId+"&token="+token+"&id="+inbox_id;
        $http.get(single_inbox_mail).success(function(response) {
        $scope.single_message = response[0];
       });
Run Code Online (Sandbox Code Playgroud)

HTML视图

<div class="page" data-ng-controller="InboxController">
  <div class="row" ng-init="single_mail()">
    <div class="mail-header row">
      <div class="col-md-8">
        <h3>{{single_message.subject}}</h3>
        <h4>From : <strong>{{inbox_from}}</strong></h4>
      </div>
    </div>
    <div class="mail-content">
      <p>{{single_message.body}}</p>
    </div>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

Gir*_*ish 11

这是编码的url部分,你应该使用decodeURIComponent()函数并在第一个参数中传递编码的字符串,参见示例代码

decodeURIComponent("john%20doe");
//> john doe
Run Code Online (Sandbox Code Playgroud)