创建了一个节点,为什么点击添加却没添加成功?代码如下:
-------------------------------------------------------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0022)http://localhost:1634/ -->
<html>
<head>
    <title>学习经历维护</title>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
    <script type="text/javascript" src="js/jquery-1.8.3.js"></script>
    <link
        rel="stylesheet" type="text/css" href="css/default.css">
    <link
        rel="stylesheet" type="text/css" href="css/style.css">
    <meta name="GENERATOR" content="MSHTML 8.00.7600.16385">
    <style type="text/css">
        td {
            background-color: #fff;
        }        th {
            background-color: #dddddd;
            text-align: left;
            width: 33%;
        }
    </style>
    <script src="js/jquery-1.8.3.js"></script>
    <script>
//添加节点
        $(function () {
            var $input = $('<tr><td><input type="text"/></td><td><input type="text"/></td><td><input type="text"/></td>');            $('table').append($input);
            $('#add').click(function () {
                $('table').append($input);
            });
        });
    </script></head>
<body>
    <div class="Edu_InfoTD">
        <form method="post"action="#" id="expForm">
            <table border="0" cellspacing="1" cellpadding="3" width="600px" bgcolor="#cccccc">
                <tr>
                    <th>学校 </th>
                    <th>开始时间 </th>
                    <th>结束时间 </th>
                </tr>
    </table>
            <div><a href="#" id="add">添加一条</a></div>
            <p>
                <input value="全部提交" type="submit">
            </p>
        </form>
    </div>
</body>
</html>

解决方案 »

  1.   

       var $input = $('<tr><td><input type="text"/></td><td><input type="text"/></td><td><input type="text"/></td>');
    ====>改为字符,要不是jquery对象,里面的dom只能出现在dom树种的一个地方,所以你在append就是添加同一个对象
                var $input = '<tr><td><input type="text"/></td><td><input type="text"/></td><td><input type="text"/></td></tr>';Web开发学习资料推荐
    jQuery仿excel表格单元格合并插件
    jquery全年日期选择器日历插件