2016-04-27 9 views
0

プロパティ "contenteditable = false"のテーブルを持っています プロパティ "contenteditable = false"を持たないカラムにプロパティ "contenteditable = falsecolumns"を追加する必要がある場合は、 、 Javascriptでそれを行う方法?すべての列にプロパティを追加しますプロパティをcontentditableに変更します。

コード:

私はあなたがループを持って見るので、私が調整されます

Javascriptを

$(document).ready(function() { 
     $('.editbtn').click(function() { 
      var currentTD = $(this).parents('tr').find('td'); 
      alert(currentTD); 
      if ($(this).html() == 'Edit') {     
       $.each(currentTD, function() { 
        $(this).prop('contenteditable', true) 
       }); 

<thead> 
    <tr> 
     <th width="40%"> 
       Col1 
     </th> 
     <th width="40%"> 
       Col2 
     </th> 
      <th width="20%"> 
     </th> 
    </tr> 
</thead> 
    <tr data-id=111> 
     <td class='col1' contenteditable="false">A</td> 
     <td class='col2'>B</td> 
     <td><button class="editbtn">Edit</button></td> 
    </tr> 

答えて

0

私のコードはあなたのものです。あなたはこのように値を設定しない場合も

$.each(currentTD, function() { 
    if (!$(this).attr("contenteditable")) 
    ;// item doesn't have this attribute 

:下記のようにあなたは、if文を置くことができる

$(this).prop('contenteditable', ""); 

をあなたも値が

var contenteditable = $(this).attr("contenteditable"); 
    if (!contenteditable || !contenteditable.length) 
    ; // value is empty 
を空にされていないかどうかを確認することができます
関連する問題