在javascript中动态增加HTML表格的行大小 [英] dynamically increase row size of HTML table in javascript

查看:108
本文介绍了在javascript中动态增加HTML表格的行大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是JavaScript的新手,只是学习它的基础知识.我正在做一个示例程序,创建了一个javascript程序,以在div内的html页面中显示一些数据.但它不是动态的.我有一些值,例如名称,addess,年龄和少数工作人员的状态,并使用html页面中显示上述详细信息的用户名登录.这是一个简单的程序.

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.

我想做的是,我想动态增加div或表的大小,在其中我可以显示使用详细信息,例如地址,年龄,状态等.如果某些用户有更多详细信息,那么我想添加在html页面中.我该怎么做 ?? 在home.jsp中,我有以下代码.

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>   

这是我在home.js中使用的功能

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>');
}

推荐答案

首先,您需要执行一个循环,然后在其中进行循环

First you need to do a loop and in that

您必须使用append()例如.

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

参考链接

这篇关于在javascript中动态增加HTML表格的行大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆