0

I have the following, I am creating a link dynamically I am stuck with concatenation of a split.

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>";

More specifically line 4 on the above I want to grab and print everything in the array from [1] and up how can I do this?

What I don't want is to do

link.split(/\d/)[1] + link.split(/\d/)[2]  + link.split(/\d/)[3]  + link.split(/\d/)[]

and so on.

4

3 に答える 3

3

これを使って:

link.split(/\d/).slice(1).join('') 
于 2012-12-06T11:52:11.483 に答える
1

最初のアイテムを除いて、分割して結合します。

var joined  = link.split(/\d/);
joined .shift(); // remove first item
joined .join(''); // join the array

そしてそれを次のように使用します:

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
        + joined // Add back on the back end of the split string
        + "</a>" // Close link tag off
        + "</li>";
于 2012-12-06T11:51:08.367 に答える
1

分割する必要はありません。スペースの後の文字列の一部を取得するだけです。

link.substr(link.indexOf(" ") + 1);
于 2012-12-06T11:55:40.800 に答える