【问题标题】:Check-box - how to get the data in a row if the checkbox in a row is checked?复选框 - 如果选中一行中的复选框,如何获取一行中的数据?
【发布时间】:2014-08-16 10:23:05
【问题描述】:

我想列出一份药品清单,并检查我想购买的所有药品。我曾想过使用一个复选框来检查我希望订购的所有药物,然后在单击订购按钮后将药物名称传输到 Javascript。

我对 Javascript 和 jQuery 还很陌生,所以我不确定如何进行这项工作。我搜索了其他代码,但找不到任何与我的问题相关的代码。

这是我制作的表格代码:

 <table id="example1" >
    <thead>
        <tr>
            <th></th>
            <th>Brand Name</th>
            <th>Medicine Name </th>
            <th>Price</th>


        </tr>
    </thead>
    <tbody>


        <tr>
            <td style="width: 5px"><input type="checkbox" /></td>                                               
            <td>Xeloda</td>
            <td> Capecitabine</td>
            <td>$150 </td>
        </tr>
        <tr>
            <td style="width: 5px"><input type="checkbox" /></td>                                               
            <td>Camptosar</td>
            <td>Irinotecan Hydrochloride</td>
            <td>$200 </td>
        </tr>
        <tr>
            <td style="width: 5px"><input type="checkbox" /></td>                                               
            <td>Eloxatin</td>
            <td>Oxaliplatin</td>
            <td>$150 </td>
        </tr>




</table>
<input type="button" value="order" onclick="getAllMedicineNameOfCheckedBox()"/>

【问题讨论】:

    标签: javascript jquery html checkbox html-table


    【解决方案1】:
    $(":checked").closest("tr").children("td").get()
    

    将返回一行中所有 td 元素的数组。您将需要做一些额外的代码,处理多个复选框等,并可能将其绑定到点击处理程序。

    $("input:checkbox").on("click", function(){
      if ($(this).is(":checked")){
          var data = $(this).closest("tr").children("td").get();
    
          /*  loop over TD items.  */
      } 
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-04
      • 1970-01-01
      • 2017-10-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多