2017-03-03 52 views

回答

3

我想你應該瀉setAttribute這樣的:

a.setAttribute('href', 'http://www.facebook.com/'); 

a.setAttribute('target', '_blank'); 

據只需要兩個參數docs

+0

哇,謝謝,它的工作原理! – ZiSean

0

setAttribute方法只接受2參數

  1. 名稱是屬性作爲字符串的名稱。
  2. 值是屬性所需的新值。

var a = document.createElement('a'); 
    a.appendChild(document.createTextNode(contacts[i][j])); 
    a.setAttribute('href', 'http://www.facebook.com/'); 
    a.setAttribute('target', '_blank'); 
    td.appendChild(a);