我有以下幾點,我正在創建一個動態鏈接,我堅持拼接的分裂。字符串數組的串聯
link = "<li><span id='number'>" + link.split(" ")[0] + ".</span>" // Adding a "peroid" character after the reason number and make it bold
+ "<a href='#" + reasonTitle + "' " // Open link tag off adding href with relevant reference
+ "onclick=\"_gaq.push([\'_trackEvent\', \'" + experimentConversionReference + "\', \'ReasonClicked\', \'" + reasonTitleSpaces + "\'])\;\">" // Adding event tracking for google
+ link.split(/\d/)[1] // Add back on the back end of the split string
+ "</a>" // Close link tag off
+ "</li>";
以上我想抓住從[1]
和最多打印數組中的一切,我怎麼能做到這一點。更具體line 4
?
我不希望是做
link.split(/\d/)[1] + link.split(/\d/)[2] + link.split(/\d/)[3] + link.split(/\d/)[]
等。
您應該考慮採用模板框架,例如https://github.com/janl/mustache.js。 – Henrik
增加一些輸入和期望的輸出將有助於理解問題。 – xtofl