Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
163 views
in Technique[技术] by (71.8m points)

jquery - dynamically increase row size of HTML table in javascript

I am new to JavaScript and just learning the basics of it. I am doing a sample program and crated a javascript program to show some data in a html page inside div. but it is not dynamic. I have some values like name, addess, age and status of few staff and while log in with a user name showing the above details in html page. this is a simple program.

What i want to do is, i want to dynamically increase the size of the div or table where i can display details of use like address, age, status etc.. if some user has more details then i want to add that in the html page. how can i do it ?? in home.jsp i have the following code.

<table>
    <div id="name1" width:400px;"></div>
    <div id="address1" width:400px;"></div>
    <div id="age1" width:400px;"></div>
    <div id="status1" width:400px;"></div>
</table>   

this is the function i use in home.js

function(json)
{   
    var content= $('#name1').replaceWith('<tr><td> Name: ' + json.name + '<tr><td>');
    var content= $('#address1').replaceWith('<tr><td> Name: ' + json.address + '<tr><td>');
    var content= $('#age1').replaceWith('<tr><td> Name: ' + json.age + '<tr><td>');
    var content= $('#status1').replaceWith('<tr><td> Name: ' + json.status + '<tr><td>');
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

First you need to do a loop and in that

You have to use append() ex.

$( "#your_div_id" ).append( "<tr><td> your_label: ' + json.your_values + '<tr><td>'" );

Reference Link


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...