0

複製されたテーブルからのクリックイベントによって複製された行があります。それが属性名を設定できない理由かどうかはわかりませんが、クリアするために2回目に複製されました。

var ipCount = 2;
$("#input_form").on("click", "#add_input_param", function() {
    $('#input_param tr').eq(1).clone().find('input').val('').end()
            .appendTo('#input_param > thead').trigger('creat')
            .find('*[name]')
            .each(function() {
       //alert(i);
       alert( $(this).attr('name'));
        $(this).setAttribute = ('name', 'new_name');
            });
    ipCount++;
});

私の質問は次のとおりです。1.属性を取得できるのに設定できないのはなぜですか。2. .each(function(){}) が、このクリック イベントによって作成された最後の行だけをループするようにします。(現在表示されているようにすべてが表示されるわけではありません)

どんな助けでも私はそれを感謝します。ありがとうございます。

これは私の HTML ブロックです:

    <h4>
                        3.3.5 Input Parameters
                    </h4>
                    <table id="input_param" >
                        <thead>
                            <tr>
                                <th>Parameter</th>
                                <th>Data Type</th>
                                <th>Required</th>
                                <th>Brief description</th>
                                <th>Location in Request</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td><input type="text" name=":ops1/6/1/1_param" /></td>
                                <td><input type="text" name=":ops1/6/1/1_type" /></td>
                                <td>
                                    <select id="required" name=":ops1/6/1/1_required">
                                        <option value="Mandatory" >Mandatory</option>
                                        <option value="Optional" >Optional</option>
                                        <option value="Conditional" >Conditional</option>
                                    </select>
                                </td>
                                <td><textarea name=":ops1/6/1/1_desc"></textarea></td>
                                <td>
                                    <select name=":ops1/6/1/1_location">
                                        <option value="Header" >Header</option>
                                        <option value="Body" >Body</option>
                                        <option value="Query_param" >Query Parameter</option>
                                        <option value="Resource_uri" >Resource URI</option>
                                    </select>
                                </td>
                            </tr>
                        </tbody>
                    </table>     
                    <input type="button" id="add_input_param" value="+ Add Input Parameter" data-inline="true" /><br />
4

1 に答える 1

2

現在、コードが適切にフォーマットされていません。

これ

 $('#input_param tr').eq(1).clone().find('input').val('').end()
        .appendTo('#input_param > thead').trigger('creat')
        .find('*[name]')
        .each(function() {
   //This is working.
   alert( $(this).attr('name'));
   //This is not working.
   $(this).attr("name", "new_name"
        });

する必要があります

 $('#input_param tr').eq(1).clone().find('input').val('').end()
        .appendTo('#input_param > thead').trigger('creat')
        .find('*[name]')
        .each(function() {
   //This is working.
   alert( $(this).attr('name'));
   //This is not working.
   $(this).attr("name", "new_name"); //<-- added );
        });
于 2013-09-17T19:18:00.433 に答える