html怎么增加一行


当前第2页 返回上一页

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

<!DOCTYPE html>

<html>

<head>

    <meta charset="UTF-8">

    <title>新增一行</title>

</head>

<body>

  

<table>

    <tr>

        <th>序号</th>

        <th>姓名</th>

        <th>电话</th>

        <th>地址</th>

        <th>操作</th>

    </tr>

  

    <!--这一行是隐藏的,主要用户方便js中获取html代码-->

    <!--##:js中会替换成数字-->

    <tr id="show" style="display: none">

        <td>##</td>

        <td>

            <input id="name##" />

        </td>

        <td>

            <input id="phone##" />

        </td>

        <td>

            <input id="address##" />

        </td>

        <td>

           <button type="button" onclick="deleteRow('##')">删除</button>

        </td>

    </tr>

</table>

<button type="button" onclick="addRow()">新增一行</button>

  

  

<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>

<script >

    var index = 0;//初始下标

    var indexArr= new Array();

  

    //新增一行

    function addRow() {

        index++;

        indexArr.push(index);

  

        var showHtml = $("#show").html();

        var html = "<tr id='tr##'>"+showHtml+"</tr>";

        html = html.replace(/##/g,index);//把##替换成数字

  

        $("#show").before($(html));

  

        console.log("当前下标数组",indexArr);

    }

  

    //删除一行

    function deleteRow(inde){

        $("#tr" + inde).remove();

        var a = indexArr.indexOf(parseInt(inde));

  

        if (a > -1) {

            indexArr.splice(a, 1);

            console.log("当前下标数组",indexArr);

        }

  

    }

</script>

</body>

</html>

【推荐学习:html视频教程】

以上就是html怎么增加一行的详细内容,更多文章请关注木庄网络博客

返回前面的内容

相关阅读 >>

javascript中对Html中元素属性的读取

Html中span是什么意思

Html中相对路径和绝对路径的区别

Html里无法显示背景颜色的解决方法

Html中怎么把div居中

Html文本区域大小怎么设置

Html中如何加载本地图片

实例详解Html如何实现文件间自由切换

用canvas实现简单的下雪效果(附代码)

Html bdo标签是什么意思?Html bdo的使用方法详解

更多相关阅读请进入《Html》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...