每行一个表包含表?

时间:2014-08-01 10:08:35

标签: javascript jquery

每当我点击"添加表"它应该创建一个表格行,每当我点击"添加行"它应该向表添加内容,它应该附加到相应的行。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />        

    <script type="text/javascript" src="./jquery-1.7.min.js"></script>
    <script type="text/javascript">
        var cnt = 1;

        function remove_row(button) {
            alert($(button).parent().parent());
            //alert($(button).parent().parent().remove());
            alert($(button).parent( "div" ).remove());
        }

        function add_info(button, id) {
            alert($(button).closest(phoneno).value)
            var drop1 = document.getElementById("drop1").value;
            var drop2 = document.getElementById("drop2").value;
            var drop3 = document.getElementById("phoneno").value;
            var appendText = "<tr><td><table><tr><td>" + drop1 + "</td><td>" + drop2 + "</td><td>" + drop2 + "</td><td>" + drop3 + "</td></table></td></tr>";
            $("div:last").after(appendText);
        }

        function add_table(obj, clicked_id) {
            alert(clicked_id);
            var appendTxt= "<div id='row'><tr><td><input type='button' value='remove row' id='remove_tr' onclick='remove_row(this)'><input type='button' hidden='hidden' id ='hidden' value='cnt'></td></tr><tr><td><select id='drop1'><option value='1'>1</option><option value='2'>2</option></select><select id='drop2'><option value='n1'>n1</option></select><input text ='text' id ='phoneno'value=''></td><td><input type='button' class='add' value='Add row' onclick='add_info(this,this.id)'/></td></tr></div>";
            $("tr:last").after(appendTxt);  
            cnt++;
        }
    </script>
 </head>

<body>       
    <table border=1 id="options-table">                 
        <tr>
            <td>
                <input type="button" class='add' id="add_table" value='Add Table' onclick="add_table(this,this.id)"/>
            </td>
        </tr>
    </table>
</body>
</html>

0 个答案:

没有答案