2016-12-14 15 views
0

こんにちは私は配列にオブジェクトを追加し、htmlの表に表示するミニプロジェクトに取り組んでいます。チェックボックスとサブミットボタンを使用してオブジェクト値を更新

各行/オブジェクトにラジオボタンがあります。チェックボックスが選択されている場合、私は自分のキーの値を更新したいと思っていました。

<div class="container"> 
    <input id="list-input" /> 
    <select id="select-status"> 
     <option value="on-going">on-going</option> 
     <option value="completed">completed</option> 
    </select> 
    <button id="add">Add To List</button> 
    <button id="update">Mark as Complete</button> 
</div> 
<div class="container"> 
    <h1>Your List</h1> 

    <div> 
     <table id="mylist"> 
      <thead> 
       <th>ID Number</th> 
       <th>Description</th> 
       <th>Status</th> 
      </thead> 
      <tbody> 
      </tbody> 
     </table> 
    </div> 
    <button id="clear">clear</button> 
</div> 

jsfiddle code

私は、アレイ内の、私のHTMLの両方で完全な状態のSAをマークしたかったです。 上記のヘルプに本当に感謝します

答えて

1

このコードは各行を通り、チェックボックスを調べ、チェックされていればテーブルと配列を更新します。これが受け入れられたとしてだけで答えをマーク助けた場合

$('#update').on('click', function() { 
    var rows = $("#mylist tbody tr"); 

    $.each(rows, function(i, row) { 
     if($(this).find('td').eq(3).find("input").is(":checked")) { 
      $(this).find('td').eq(2).text("complete"); 
      tasks[i].status = "complete";    
     } 
    }); 

    // This console.table is here so you can see that the array is updated. 
    // You can remove it when you are satisfied this works. 
    console.table(tasks); 

}); 
+0

はあなた洙多くの先生 – Jorge

+0

に感謝:http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work –

関連する問題