1. 程式人生 > >Js 添加動態修改id

Js 添加動態修改id

input ace htm table tr roo net [0 oom html

//HTML代碼
    
        <table id="templateTable" >
            <tr>
                <td id="oneTd"  >
                    <div class="control-group">
                        <label class="control-label required"> <span
                            class="help-inline"><font color="red">*</font> </span>房間類型:
                        
</label> <div class="controls"> <input type="text" name="roomType" id="roomType1" required="required" onblur="quchong(1)"/> </div> </div> </tr> </table>
//js

<script>    
    function addTr() {
        m = templateTable.rows[0].cells.length
        n = m + 1;
        var trHtml = $("#templateTable1 tr :first").html();
        trHtml = trHtml.replace(id="roomType1",id="roomType"+n);

        trHtml = trHtml.replace(onblur="quchong(1)",onblur="quchong"+"("+n+")");
        $(
"#templateTable tr").append(trHtml); } </script>

Js 添加動態修改id