简体   繁体   English

基于单元格值jquery更新表行

[英]Update table row based on cell value jquery

I have a contacts table that contains a column for contact_id . 我有一个联系人表,其中包含用于contact_id的列。 Can someone help me update a table row based on contact_id ? 有人可以帮我根据contact_id更新表格行吗? For example, I have the following table: 例如,我有下表:

<table class="table table-condensed" id="company_contacts_table">
    <thead>
      <tr>
        <th>First Name</th>
        <th>Last Name</th>
        <th>Email</th>
        <th>Phone #</th>
        <th>Notes</th>
        <th></th>
        <th></th>
      <th hidden></th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>Jake</td>
        <td>Dang</td>
        <td>jake123@gmail.com</td>
        <td>7032669955</td>
        <td>contact_notes</td>
        <td><button type="update" class="btn btn-primary update_contact" href="#update_contact_modal" data-toggle="modal" id="some_contact_id">Update</button></td>
        <td><button type="update" class="btn btn-danger delete_contact" id="some_contact_id">Delete</button></td>
        <td hidden>some_contact_id</td>
      </tr>
      <tr>
        <td>Harrison</td>
        <td>WElls</td>
        <td>Hwells@gmail.com</td>
        <td>7039998888</td>
        <td>contact_notes</td>
        <td><button type="update" class="btn btn-primary update_contact" href="#update_contact_modal" data-toggle="modal" id="some_contact_id2">Update</button></td>
        <td><button type="update" class="btn btn-danger delete_contact" id="some_contact_id2">Delete</button></td>
        <td hidden>some_contact_id2</td>
      </tr>
      <tr>
        <td>Mason</td>
        <td>Hanley</td>
        <td>mnahley@gmail.com</td>
        <td>7032669855</td>
        <td>contact_notes</td>
        <td><button type="update" class="btn btn-primary update_contact" href="#update_contact_modal" data-toggle="modal" id="some_contact_id3">Update</button></td>
        <td><button type="update" class="btn btn-danger delete_contact" id="some_contact_id3">Delete</button></td>
        <td hidden>some_contact_id3</td>
      </tr>
    </tbody>
</table>

Each row contains a hidden contact_id column. 每行包含一个隐藏的contact_id列。 I want to update the first name, last name, email, phone #, notes based on the contact id. 我想根据联系人ID更新名字,姓氏,电子邮件,电话号码,备注。 Sample pseudocode: 样本伪代码:

var my_contact_id = some_contact_id var my_contact_id = some_contact_id

var new_first_name = 'george'
var new_last_name = 'henry'
var new_email = 'tinpopo@hotmail.com'
var new_phone = 999-333-4444

- Find row that contains `some_contact_id`
- Set first name, last name, email, phone to new first name, new last name, new email, new phone

Can someone help? 有人可以帮忙吗?

Thanks in advance!! 提前致谢!!

var new_first_name = 'george'
var new_last_name = 'henry'
var new_email = 'tinpopo@hotmail.com'
var new_phone = 999-333-4444

var tr = $("#company_contacts_table td:contains("+some_contact_id+")").closest("tr").find("td");
tr[0].innerHTML = new_first_name;
tr[1].innerHTML = new_last_name;
tr[2].innerHTML = new_email;
tr[3].innerHTML = new_phone;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM