18910140161

JavaScript-如何在单击按钮时从表中提取动态创建的表单元格的值?-堆栈溢出

顺晟科技

2022-10-19 11:56:16

250

我正在动态创建一个表,每一行都有一个按钮。单击按钮后,OI希望提取该行的单元格值。

HTML:

<table class="table table-hover table-bordered" id="alterationsTable">
    <thead>
        <tr>
          <th>Date</th>
          <th>Problem/Event</th>
          <th>Discuss</th>
          <th>Outcome Modification</th>
          <th>Add/Update</th>
        </tr>
    </thead>
    
    <tbody id="alterationsTablebody">
        <tr>
            <!-- Place for training alterations/notes details -->
        </tr>
    </tbody>                
</table>

要创建的JS:

<table class="table table-hover table-bordered" id="alterationsTable">
    <thead>
        <tr>
          <th>Date</th>
          <th>Problem/Event</th>
          <th>Discuss</th>
          <th>Outcome Modification</th>
          <th>Add/Update</th>
        </tr>
    </thead>
    
    <tbody id="alterationsTablebody">
        <tr>
            <!-- Place for training alterations/notes details -->
        </tr>
    </tbody>                
</table>

$(html).appendto($(“#AlterationStableBody”));

要提取的JS:

<table class="table table-hover table-bordered" id="alterationsTable">
    <thead>
        <tr>
          <th>Date</th>
          <th>Problem/Event</th>
          <th>Discuss</th>
          <th>Outcome Modification</th>
          <th>Add/Update</th>
        </tr>
    </thead>
    
    <tbody id="alterationsTablebody">
        <tr>
            <!-- Place for training alterations/notes details -->
        </tr>
    </tbody>                
</table>

顺晟科技:

这是我根据Abhilash的回答提出的:

要创建的JS:

<table class="table table-hover table-bordered" id="alterationsTable">
    <thead>
        <tr>
          <th>Date</th>
          <th>Problem/Event</th>
          <th>Discuss</th>
          <th>Outcome Modification</th>
          <th>Add/Update</th>
        </tr>
    </thead>
    
    <tbody id="alterationsTablebody">
        <tr>
            <!-- Place for training alterations/notes details -->
        </tr>
    </tbody>                
</table>

要提取的JS:

<table class="table table-hover table-bordered" id="alterationsTable">
    <thead>
        <tr>
          <th>Date</th>
          <th>Problem/Event</th>
          <th>Discuss</th>
          <th>Outcome Modification</th>
          <th>Add/Update</th>
        </tr>
    </thead>
    
    <tbody id="alterationsTablebody">
        <tr>
            <!-- Place for training alterations/notes details -->
        </tr>
    </tbody>                
</table>

嘿,您试图从td元素访问值,但实际值将存储在td元素内部的input元素中。检查代码段。

  • TAG:
相关文章
我们已经准备好了,你呢?
2024我们与您携手共赢,为您的企业形象保驾护航