Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/464.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 追加和链接_Javascript_Jquery - Fatal编程技术网

Javascript 追加和链接

Javascript 追加和链接,javascript,jquery,Javascript,Jquery,这是由.append函数中的错误引起的吗?您需要在href属性上加引号: { "by" : "patrickgokey", "id" : 8441055, "kids" : [ 8441399, 8441097, 8441985, 8441301, 8441852, 8441578, 8441287, 8441389, 8441586, 8441583, 8441584, 8441449, 8441380 ], "score" : 161, "text" : "", "t

这是由.append函数中的错误引起的吗?

您需要在
href
属性上加引号:

{
  "by" : "patrickgokey",
  "id" : 8441055,
  "kids" : [ 8441399, 8441097, 8441985, 8441301, 8441852, 8441578, 8441287, 8441389, 8441586, 8441583, 8441584, 8441449, 8441380 ],
  "score" : 161,
  "text" : "",
  "time" : 1412995787,
  "title" : "Core Secrets: NSA Saboteurs in China and Germany",
  "type" : "story",
  "url" : "https://firstlook.org/theintercept/2014/10/10/core-secrets/"
}

这取决于您的json数据。您需要显示导致问题的数据,以便我们可以复制它。这似乎是准确的:
<p><a href="http://www.vanityfair.com/business/2014/11/satya-nadella-bill-gates-steve-ballmer-microsoft.print">The Microsoft Empire Reboots</a> 8441095</p>
<p><a href="https://firstlook.org/theintercept/2014/10/10/core-secrets"></a>Core Secrets: NSA Saboteurs in China and Germany 8441055</p>
{
  "by" : "patrickgokey",
  "id" : 8441055,
  "kids" : [ 8441399, 8441097, 8441985, 8441301, 8441852, 8441578, 8441287, 8441389, 8441586, 8441583, 8441584, 8441449, 8441380 ],
  "score" : 161,
  "text" : "",
  "time" : 1412995787,
  "title" : "Core Secrets: NSA Saboteurs in China and Germany",
  "type" : "story",
  "url" : "https://firstlook.org/theintercept/2014/10/10/core-secrets/"
}
if (json["type"] == "story") {
    $(".title").append("<p><a href='" + json["url"] + "'>" + json["title"] + "</a> " + json["id"] + "</p>");
}
<a href=https://firstlook.org/theintercept/2014/10/10/core-secrets/> <--Closes the tag