相关疑难解决方法(0)

用Jquery选择id by id

我正在尝试在表格中选择一个tr来删除它,但我没有选择器的运气.

表看起来像这样:

<table width="301" border="0" cellspacing="5" cellpadding="0" id="selectedproducts" =="">
      <tbody>
        <tr>
          <th width="56" scope="col">Product:</th>
          <th width="48" scope="col">Size:</th>
          <th width="71" scope="col">Colour:</th>
          <th width="41" scope="col">Qty</th>
          <th width="55" scope="col">Price</th>
          <th width="55" scope="col">Delete</th>
        </tr>
        <tr id="product_1">
          <td>Shuttle</td>
          <td>54.95</td>
          <td>Red</td>
          <td>1</td>
          <td></td>
          <td><a onclick="deleteProduct(id)">[X]</a></td>
        </tr>
        <tr id="product_2">
          <td>Shuttle</td>
          <td>54.95</td>
          <td>Red</td>
          <td>1</td>
          <td></td>
          <td><a onclick="deleteProduct(id)">[X]</a></td>
        </tr>
      </tbody>
 </table>
Run Code Online (Sandbox Code Playgroud)

带有产品ID的tr是动态附加jQuery所以不确定是否会产生影响.

deleteProduct(id) 功能看起来像这样:

function deleteProduct(id) {
 $('#product_' + id).remove();
}
Run Code Online (Sandbox Code Playgroud)

点击后没有任何操作,Chrome控制台中没有错误.

在控制台中捣乱一下:

$('#selectedproducts').html();返回数据 $('#selectedproducts').find('#product_1').html()返回空

javascript jquery html-table css-selectors

7
推荐指数
1
解决办法
7万
查看次数

标签 统计

css-selectors ×1

html-table ×1

javascript ×1

jquery ×1