2012-04-21 10 views
1

テーブルのセルに内容を表示する必要があります。jqueryを使って別のtdをクリックすることで、特定のクラス名を持つtdの値を表示する方法は?

表は以下の通りです:

<table id="innertable"> 
         <thead> 
          <tr class="tablewrapperheader"> 
           <th>Status</th> 
           <th>Date Requested</th> 
           <th>Date Time Range</th> 
           <th>Reason</th> 
           <th>Date Approved/Denied</th> 
           <th>Reason Denied</th> 
           <th>Approve/Deny</th> 
          </tr> 
         </thead> 
         <tbody> 
          <tr class="odd"> 
           <td id="check" class="pending"><img src="../images/icons/36x36/exclamation.gif" alt="exclamation"/> 
            &nbsp;<span id="checkMsg">Pending</span></td> 
           <td>06/15/2012</td> 
           <td>06/21/2012</td> 
           <td>Medical Checkups</td> 
           <td class="dateApproveDenied"></td> 
           <td class="reasonDenied"></td> 
           <td><img src="../images/icons/128x128/approve.png" class="actionApprove" alt="exclamation" height="16" width="16"/>&nbsp;&nbsp;<img src="../images/icons/128x128/deny.png" class="actionDeny" alt="" height="16" width="16"/></td> 
          </tr> 

ユーザーがアクティブにクリックするか、拒否し、拒否した場合、彼らは拒否の理由を与える必要があります。私は、拒否の日付と理由を、私がクラス名 "dateApproveDenied"と "reasonDenied"を使用している、尊重されたtdに表示しなければなりません。私はこの影響を達成するためにJqueryを使用していますが、無駄です。

は、ここで私はその理由が、その理由を書いて、日付がTDに表示されないために、プロンプトを取得し、私のjqueryの

$(".actionDeny").click(function(){ 

    var reason = prompt("Write reason for denial.",''); 
    var today = new Date(); 
    var dd = today.getDate(); 
    var mm = today.getMonth()+1; //js months 0-11 
    var yyyy = today.getFullYear(); 
    if(dd<10){ 
     dd='0'+dd 
    } 
    if(mm<10){ 
     mm='0'+mm 
    } 
    var today = mm+'/'+dd+'/'+yyyy; 
    $(this).closest('td .dateApproveDenied').text(today); 
    $(this).closest('td .reasonDenied').text(reason); 
}); 

です。誰かが私にそれを正しく設定するのを助けてください。ありがとう

+0

を、 'reasonDenied'は' id'ですが、あなたのjQueryのセレクタは 'としてそれを見つけようとしていますクラス '。 – David

+0

ご協力いただきありがとうございます。私は自分のコードでそれを修正し、同様に....しかし、私はまだtdの値を取得していません。 – Parth

答えて

1

親trを取得するために最も近い値を使用し、次にtdsを見つけます。

$(this).closest('tr').find('.dateApproveDenied').text(today); 
$(this).closest('tr').find('.reasonDenied').text(reason); 

編集

あなたにも最も近いセレクタをキャッシュすることができます初心者のために

var $tr = $(this).closest('tr'); 
$tr.find('.dateApproveDenied').text(today); 
$tr.find('.reasonDenied').text(reason); 
+0

ありがとうございました.....それは今働いています....... – Parth

関連する問題