2015-09-21 84 views
0

我如何使用我的id表更改jQuery中的th值?我想獲得我的價值,並在點擊按鈕時更改它,但我不知道如何獲得th屬性。jquery更改th值

 <div class="col-md-2 col-md-offset-1"> 
     <div class="panel panel-default"> 
      <table id="table1" class="table"> 
      <thead> 
       <th class="text-center">My header</th> 
      </thead> 
      <tbody> 
       <tr> 
       <td>Category<input type="checkbox"/></td> 
       </tr> 
      </tbody> 
      <tfoot> 
       <tr> 
       <td> 
        <button type="button" class="btn btn-danger">Choose</button> 
       </td> 
       </tr> 
      </tfoot> 
      </table> 
     </div> 
     </div> 
+0

'$('#tableid')。find('thead')' – guradio

回答

1

我怎樣才能改變在JQuery中的日值與我的ID表

個元素沒有價值關聯他們。如果你的意思是它的內容,那麼你可以使用.text().html()連同選擇器:

$('#tableid tg').text(); // My header 

我想我THEAD日的價值和改變它,當我點擊

您可以使用.text().html()新內容作爲參數來設置新的內容

$('#tableid tg').text('New Header'); 
+0

謝謝大家!文本屬性完美地工作。 – John

+0

@約翰:很高興它有幫助 –

1

您可以使用:

$("#table1 thead th").text("Different header text"); 
1
var value = $('th', '#table1').html(); //"My header" 
$('th', '#table1').html('new value'); //sets "new value"