开发者

How can I start with <a href=" and have an array element here then end with </a>?

The thing im trying to do right now is pulling in multiple links from a textarea,

We can pretend that a user inputs c:\pics\img01.jpg and in the next row he'll have the next imglink.

I want to pull those links, I allready have the code for that:

var entered = $('#filedir').val();  
var lines = entered.split(/\r\n/);  
var opttext = "";  
for(var i=0;i<lines.length;i++) {  
    opttext += '< img src="' + lines[i] + '">< /img>';
}
​

the problem is in the output which is:

< img src="file:///C:/pics/img01.jpgc:/pics/img02.jpg">< /img>

There should be two < img> elements..

Where am I going wrong? I've been at it f开发者_开发百科or a bit over 2 hours now..


It's likely that your lines aren't getting split correctly and you're ending up with one long line in the array. Try this instead:

var lines = entered.split(/\n/);  


for(var i=0;i<lines.length;i++)
{
     opttext += '<img src="' + lines[i] + '"></img>';
}

Your for loop was incorrect.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜