删除链接周围的引号

时间:2016-04-23 11:17:13

标签: javascript json

我有公司列表的公司数据,我能够点击特定名称并为该特定公司生成数据的唯一方法是为一行代码company = '"'+company+'"';添加引号。如果没有添加引号,则单击该特定公司名称的数据不会显示。

我不喜欢引号的外观,而且我没有运气使用str_replace()。这是代码:

function findCompanies()
{
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (xhttp.readyState == 4 && xhttp.status == 200) {
      var companies = JSON.parse(xhttp.responseText);
      var list = "<p>There are totally "+companies.totalResults+" companies of which the 10 first are listed here.</p>";
      var nrofcomp = companies.totalResults;

      if (nrofcomp>10){
          nrofcomp = 10;
      }

      for (i=0;i<nrofcomp;i++)
      {
       company = companies.results[i].name;  
       company = '"'+company+'"';        //QUOTE AROUND COMPANY NAME    
       list = list + "<a href='#/' onclick='findCompanyData("+company+");'>"+company+"</a><br/>";
      }
      document.getElementById("ansver").innerHTML = list;
    }
  }
  url ="http://avoindata.prh.fi:80/tr/v1?totalResults=true&maxResults=10&resultsFrom=0&registeredOffice="+document.input.city.value+"&companyRegistrationFrom="+document.input.start.value+"&companyRegistrationTo="+document.input.end.value;
  xhttp.open("GET", url, true);
  xhttp.send();      
}

如果没有公司名称周围的引号,链接(显示该公司的信息)根本不起作用。

以下是它的外观:

enter image description here

有什么建议吗?

0 个答案:

没有答案