3

以下のコードがあるとしましょう:

 textInput = $('#outputTextInput').val();

   $('#outputAdd').click(function(){

       $('#status_table tr:last').after('<tr id="output_newrow_"+textInput><td>1</td><td id="type_row_"+textInput>lala</td><td id="num_row_"+textInput>num row '+textInput+'</td><td><img class="image" src="static/OffLamp-icon.png" style="height:64px; width=64px"/></td></tr>');

    });
   $('#outputRemove').click(function(){

        $('#status_table').find("#output_newrow_"+textInput).remove();


   });

次に、ID「output_newrow_」+textInputまたは「type_row_」+textInputでそのセレクターを呼び出したい...

$('#how_should_i_write_it_here').append(textInput)

そのセレクターをどのように呼び出すべきかわかりません...

すべての助けを前もってありがとう:)

アップデート!ここにフィドルのリンクがあります。私の問題は、変数「textInput」を表示できず、数回追加および削除するとインデックス番号が乱雑になることです。たとえば、「1,2,3」と入力すると、テーブルにインデックス 2,3,4 が表示されます。しかし、3 を入力して [削除] をクリックすると、代わりにインデックス 2 (1 にリンクすると想定される) が削除されます。

4

3 に答える 3

2

コード内の文字列連結が間違っています。コード内でindexundefined.

$('#outputAdd').click(function(){
   var textInput = $('#outputTextInput').val();
   var str = '<tr id="output_newrow_' +textInput + '">'
               + '<td>1</td><td id="type_row_' + textInput '">lala</td>'
               + '<td id="num_row_' + textInput + '">num row ' + textInput + '</td>'
               + '<td><img class="image" src="static/OffLamp-icon.png" style="height:64px; width=64px"/></td>'
          +  '</tr>';
   $('#status_table tr:last').after(str);

});
$('#outputRemove').click(function(){
    $("#output_newrow_"+textInput).remove();
});
于 2013-04-22T08:27:00.407 に答える
0

あなたがそれを割り当てる方法とほとんど同じです。このような:

$("#output_newrow_" + textInput).appen(textInput);
于 2013-04-22T04:03:30.130 に答える
0

文字列の連結が間違っていました

$('#outputAdd').click(function(){
    var textInput = $('#outputTextInput').val();

    $('#status_table tr:last').after('<tr id="output_newrow_'+textInput+'"><td>1</td><td id="type_row_"+textInput>lala</td><td id="num_row_"+textInput>num row '+index+'</td><td><img class="image" src="static/OffLamp-icon.png" style="height:64px; width=64px"/></td></tr>');

});
$('#outputRemove').click(function(){
    $('#status_table').find("#output_newrow_"+textInput).remove();    
});
于 2013-04-22T03:59:37.217 に答える