admin管理员组文章数量:1406016
I am very new to web development and under major deadline. I would really appreciate your help on this.
I have an array which gets created through a javascript function which runs when user clicks on a particular table on the webpage.
<tr id="table1_1_1_0">
<td><a href="#" onclick="func_get_fields('table1_1_1_0');">Primary</a></td>
</tr>
This function func_get_fields creates an array List_of_Screen_Names which has entries to be displayed.
My question is how do I display the elements of this returned array in the webpage so that each of them is a link in itself.
I found some code which works with the php arrays but not with javascript.
How can i do this ?
I tried another approach
document.write('<table border="1" cellspacing="1" cellpadding="5">')
for(i = 0; i < List_of_Screen_Names.length; i++){
document.write('<tr><td>');
document.write(List_of_Screen_Names[i]);
document.write('</td></tr>');
}
document.write('</table>');
This creates a table of strings which I think can be changed to links. But it pletely wipes off the webpage and shows only the table. How to make it display within a div.
I am very new to web development and under major deadline. I would really appreciate your help on this.
I have an array which gets created through a javascript function which runs when user clicks on a particular table on the webpage.
<tr id="table1_1_1_0">
<td><a href="#" onclick="func_get_fields('table1_1_1_0');">Primary</a></td>
</tr>
This function func_get_fields creates an array List_of_Screen_Names which has entries to be displayed.
My question is how do I display the elements of this returned array in the webpage so that each of them is a link in itself.
I found some code which works with the php arrays but not with javascript.
How can i do this ?
I tried another approach
document.write('<table border="1" cellspacing="1" cellpadding="5">')
for(i = 0; i < List_of_Screen_Names.length; i++){
document.write('<tr><td>');
document.write(List_of_Screen_Names[i]);
document.write('</td></tr>');
}
document.write('</table>');
This creates a table of strings which I think can be changed to links. But it pletely wipes off the webpage and shows only the table. How to make it display within a div.
Share Improve this question edited Apr 8, 2014 at 7:47 John asked Apr 8, 2014 at 5:41 JohnJohn 6471 gold badge10 silver badges21 bronze badges3 Answers
Reset to default 4You can modify elements inner html with javascript. For example if you want to show the results in <div id="results"></div>
the code would be:
var myStringArray = ["http://google.","http://bing."]; //Sample array, use yours
var result = ""
for (var i = 0; i < myStringArray.length; i++) {
result = result + " <a href='" + myStringArray[i] + "'>"+ myStringArray[i] + "</a>";
}
document.getElementById('results').innerHTML = result
I hope it helps!
using "split" in javascript . it's returns array value
split
function func_get_fields(d_id)
{
var ar = d_id.split('_');
alert(ar[1]);
}
If List_of_Screen_Names
is an array of links:
for(var i=0;i<List_of_Screen_Names.length;i++){
var newLink = document.createElement('a');
newLink.innerHTML = List_of_Screen_Names[i];
document.body.appendChild(newLink);
}
本文标签: htmlHow to display each element of a javascript array as a linkStack Overflow
版权声明:本文标题:html - How to display each element of a javascript array as a link - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744960751a2634638.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论