English 中文(简体)
如何把多个阵列聚集在一起?
原标题:How can one put together multiple arrays into one string?

我花了很强的时间来描述我所期待的东西。

If we pretend that we re pulling an array (I ve used the .split to get user input data) where each line represents a link.

那么,我怎么能够给我拉开的那条联系添加一个 anchor子?

我需要能够做到这一点。

< a href=" + thearray + ">anything< /a>.

之所以如此,是因为我生动地提出一个清单。

我认为,如果我产生两个变量,一个变量与这一部分

< a href="

one with the closing and then call some sort of function that puts those two and the pulled array in between them until the list is complete.

www.un.org/Depts/DGACM/index_spanish.htm 这是否有意义?

edit: here s a link to the full code: http://hem.bredband.net/noor/thecode.txt

最佳回答

我认为你指的是:

for(var x=0;x<thearray.length;x++) {
   document.write  <a href=" + thearray[x] + ">anything</a> 
}

你只是想通过阵列内容,用一些超文本加以总结。

问题回答

您指的是,你们想要拥有像样的阵容。

["http://www.google.com", "http://www.yahoo.com", "http://www.stackoverflow.com"]

以及你希望将其变为现实

"<a href= http://www.google.com >anything</a>
<a href= http://www.yahoo.com >anything</a>
<a href= http://www.stackoverflow.com >anything</a>"

?

如果是,你可以这样做。

var myArray = ["http://www.google.com", "http://www.yahoo.com", "http://www.stackoverflow.com"];
var result = "";
for (var i=0; i<myArray.length; i++) {
   result += "<a href= " + myArray[i] + " >anything</a>";
}

否则,如果想到“我想先从X开始,最后从Y开始”,就会帮助你澄清问题。

也许你指的是:

var tagStart =  <a href=" ,
    tagEnd =  ">anything</a> ,
    html = tagStart + thearray.join(tagEnd + tagStart) + tagEnd;

我仍然建议使用一种假体,但是,如果<代码>thearray是空的,上述代码将是非实物的。

我认为,使用地图,然后加入,将更加可读:

function makeLink(url)
{
   return "<a href="" + url + "">anything</a>";
}
result = myArray.map(makeLink).join("
");

关于地图的更多信息可在





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签