单击删除时需要删除整行

发布于 2024-11-09 04:08:18 字数 5561 浏览 0 评论 0原文

   <tr>
        <td>Year</td>
        <td>Make</td>
        <td>Model</td>
        <td>Doors</td>
        <td>4 Wheel Drive</td>
    </tr>
    <tr>
        <td><input type="text" class="small_input_text required only_number" name="auto_year_'+no_fields+'" id="auto_year_'+no_fields+'" /></td>
        <td><input type="text" class="small_input_text required" name="auto_make_'+no_fields+'" id="auto_make_'+no_fields+'" /></td>
        <td><input type="text" class="small_input_text required" name="auto_model_'+no_fields+'" id="auto_model_'+no_fields+'" /></td>
        <td>
            <select name="auto_doors_'+no_fields+'" id="auto_doors_'+no_fields+'">
                <option value="2 door">2 door</option>
                <option value="4 door">4 door</option>
             </select>
        </td>
        <td>
            <select name="auto_liability_'+no_fields+'" id="auto_liability_'+no_fields+'">
                <option value="No">No</option>
                <option value="Yes">Yes</option>
            </select>
        </td>
        <td>
        <a class="remove_new" onclick="$(this).parent().parent().remove();");">x</a>
        </td>
    </tr>
    <tr>
        <td colspan="7">
        <ul class="regular_form">
            <li>
            <label class="large_label">Current Liability Limit:</label>
            <input type="text" class="medium_input_text" name="l_exp_date_'+no_fields+'" id="l_exp_date_'+no_fields+'"/>
            </li>
            <li>
            <label class="large_label">Bodily Inj. Liab.:</label>
            <select name="a_body_'+no_fields+'" id="a_body_'+no_fields+'">
                <option value="50/100">50k / 100k</option>
                <option value="100/300">100k / 300k</option>
                <option value="250/500">250k / 500k</option>
            </select>
            </li>
            <li>
            <label class="large_label">Property Damage:</label>
            <select name="a_property">
                <option value="10">10,000</option>
                <option value="25">25,000</option>
                <option value="50">50,000</option>
                <option value="100">100,000</option>
                <option value="100">250,000</option>
            </select>
            </li>
            <li>
                <label class="large_label">
                    Uninsured Motorist:</label><select name="a_unins_'+no_fields+'" id="a_unins_'+no_fields+'"><option
                        value="25/50/25">25/50/25</option>
                        <option value="50/100/50">50/100/50</option>
                        <option value="100/300/100">100/300/100</option>
                    </select></li><li>
                        <label class="large_label">
                            Collision:</label><select name="a_col_'+no_fields+'" id="a_col_'+no_fields+'"><option
                                value="250">250 Deductible</option>
                                <option value="500">500 Deductible</option>
                                <option value="1000">1,000 Deductible</option>
                            </select></li><li>
                                <label class="large_label">
                                    Comprehensize:</label><select name="a_comp_'+no_fields+'" id="a_comp_'+no_fields+'"><option
                                        value="0">0 Deductible</option>
                                        <option value="100">100 Deductible</option>
                                        <option value="250">250 Deductible</option>
                                        <option value="500">500 Deductible</option>
                                        <option value="1000">1000 Deductible</option>
                                    </select></li><li>
                                        <label class="large_label">
                                            Rental Car:</label><select name="a_rent_'+no_fields+'" id="a_rent_'+no_fields+'"><option
                                                value="$20/day">$20/day</option>
                                                <option value="$30/day">$30/day</option>
                                            </select></li><li>
                                                <label class="large_label">
                                                    Towing:</label><select name="a_towing"><option value="$100">$50</option>
                                                        <option value="$100">$100</option>
                                                    </select></li></ul>
            <a class="remove_new" onclick="$(this).parent().parent().remove();">x</a>
        </td>
    </tr>
   <tr>
        <td>Year</td>
        <td>Make</td>
        <td>Model</td>
        <td>Doors</td>
        <td>4 Wheel Drive</td>
    </tr>
    <tr>
        <td><input type="text" class="small_input_text required only_number" name="auto_year_'+no_fields+'" id="auto_year_'+no_fields+'" /></td>
        <td><input type="text" class="small_input_text required" name="auto_make_'+no_fields+'" id="auto_make_'+no_fields+'" /></td>
        <td><input type="text" class="small_input_text required" name="auto_model_'+no_fields+'" id="auto_model_'+no_fields+'" /></td>
        <td>
            <select name="auto_doors_'+no_fields+'" id="auto_doors_'+no_fields+'">
                <option value="2 door">2 door</option>
                <option value="4 door">4 door</option>
             </select>
        </td>
        <td>
            <select name="auto_liability_'+no_fields+'" id="auto_liability_'+no_fields+'">
                <option value="No">No</option>
                <option value="Yes">Yes</option>
            </select>
        </td>
        <td>
        <a class="remove_new" onclick="$(this).parent().parent().remove();");">x</a>
        </td>
    </tr>
    <tr>
        <td colspan="7">
        <ul class="regular_form">
            <li>
            <label class="large_label">Current Liability Limit:</label>
            <input type="text" class="medium_input_text" name="l_exp_date_'+no_fields+'" id="l_exp_date_'+no_fields+'"/>
            </li>
            <li>
            <label class="large_label">Bodily Inj. Liab.:</label>
            <select name="a_body_'+no_fields+'" id="a_body_'+no_fields+'">
                <option value="50/100">50k / 100k</option>
                <option value="100/300">100k / 300k</option>
                <option value="250/500">250k / 500k</option>
            </select>
            </li>
            <li>
            <label class="large_label">Property Damage:</label>
            <select name="a_property">
                <option value="10">10,000</option>
                <option value="25">25,000</option>
                <option value="50">50,000</option>
                <option value="100">100,000</option>
                <option value="100">250,000</option>
            </select>
            </li>
            <li>
                <label class="large_label">
                    Uninsured Motorist:</label><select name="a_unins_'+no_fields+'" id="a_unins_'+no_fields+'"><option
                        value="25/50/25">25/50/25</option>
                        <option value="50/100/50">50/100/50</option>
                        <option value="100/300/100">100/300/100</option>
                    </select></li><li>
                        <label class="large_label">
                            Collision:</label><select name="a_col_'+no_fields+'" id="a_col_'+no_fields+'"><option
                                value="250">250 Deductible</option>
                                <option value="500">500 Deductible</option>
                                <option value="1000">1,000 Deductible</option>
                            </select></li><li>
                                <label class="large_label">
                                    Comprehensize:</label><select name="a_comp_'+no_fields+'" id="a_comp_'+no_fields+'"><option
                                        value="0">0 Deductible</option>
                                        <option value="100">100 Deductible</option>
                                        <option value="250">250 Deductible</option>
                                        <option value="500">500 Deductible</option>
                                        <option value="1000">1000 Deductible</option>
                                    </select></li><li>
                                        <label class="large_label">
                                            Rental Car:</label><select name="a_rent_'+no_fields+'" id="a_rent_'+no_fields+'"><option
                                                value="$20/day">$20/day</option>
                                                <option value="$30/day">$30/day</option>
                                            </select></li><li>
                                                <label class="large_label">
                                                    Towing:</label><select name="a_towing"><option value="$100">$50</option>
                                                        <option value="$100">$100</option>
                                                    </select></li></ul>
            <a class="remove_new" onclick="$(this).parent().parent().remove();">x</a>
        </td>
    </tr>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

请叫√我孤独 2024-11-16 04:08:18

假设您在要删除的行的 内有一个按钮、链接或其他内容,您可以执行类似以下代码的操作。

  • 神奇之处在于:$(this).closest('tr').remove()——最接近的将在 DOM 中向上查找 tr 元素。如果您想快速修复代码,请尝试 onclick="$(this).closest('tr').remove();"

HTML

<table>
  <tbody>
   <tr>
     <td>Row 1</td>
     <td><input type="button" class="remove_row" value="Remove Row"/></td>
   </tr>
   <tr>
     <td>Row 2</td>
     <td><input type="button" class="remove_row" value="Remove Row"/></td>
   </tr>
  </tbody>
</table>

jQuery

$('.remove_row').live('click', function() {
    $(this).closest('tr').remove();
});

Fiddle 示例: http://jsfiddle.net/garreh/ernnP/
使用 .live 假设您将来希望具有添加行的功能。

Assuming you had a button, link or something inside a <td> of the row you want removed, you could do something like the code below.

  • The magic is: $(this).closest('tr').remove() -- closest will travel up the DOM finding the tr element. If you wanted a quick fix for your code, try onclick="$(this).closest('tr').remove();"

HTML

<table>
  <tbody>
   <tr>
     <td>Row 1</td>
     <td><input type="button" class="remove_row" value="Remove Row"/></td>
   </tr>
   <tr>
     <td>Row 2</td>
     <td><input type="button" class="remove_row" value="Remove Row"/></td>
   </tr>
  </tbody>
</table>

jQuery

$('.remove_row').live('click', function() {
    $(this).closest('tr').remove();
});

Fiddle example: http://jsfiddle.net/garreh/ernnP/
Use of .live is assuming in the future you want to have a functionality of adding a row.

情感失落者 2024-11-16 04:08:18

我在该代码中看到的唯一直接错误是:

onclick="$(this).parent().parent().remove();");"

...最后有一个额外的 );"。它应该是:

onclick="$(this).parent().parent().remove();"

它位于第一个两个 元素。

The only immediate error that I can see in that code is this:

onclick="$(this).parent().parent().remove();");"

...you have an extra );" at the end. It should be:

onclick="$(this).parent().parent().remove();"

It's on the first both <a> elements.

臻嫒无言 2024-11-16 04:08:18

您的代码中有一些语法错误,让我们只看一下删除链接

<a class="remove_new" onclick="$(this).parent().parent().remove();");">x</a>

这可能应该是

<a class="remove_new" onclick="$(this).parent().parent().remove();">x</a>

最好按照这样的方式做一些事情

<a class="remove_new" onclick="$(this).closest('tr').remove();">x</a>

这样您就不必依赖 DOM 的稳定性并且它应该可以工作,我尝试在 JsFiddle 中测试它,但代码中的某些内容与 JsFiddle 混淆,并且它无法正确导入 jQuery。

将来,如果您很好地格式化代码并且可以提供简化的案例,您可能会更快地得到答案。

You have some syntax errors in your code, let's look at just the removal link

<a class="remove_new" onclick="$(this).parent().parent().remove();");">x</a>

This should probably be

<a class="remove_new" onclick="$(this).parent().parent().remove();">x</a>

It's probably better to do something along the lines of

<a class="remove_new" onclick="$(this).closest('tr').remove();">x</a>

That way you don't have to depend on the stability of the DOM and it should work, I tried testing it in JsFiddle but something in your code is messing with JsFiddle and it won't import jQuery correctly.

In the future you will probably get an answer more quickly if you nicely format your code and if you can provide a simplified case.

默嘫て 2024-11-16 04:08:18

http://jsfiddle.net/orolo/bnZwg/

$('.remove_new').click(function() {
    $(this).parent().parent().remove();
});

http://jsfiddle.net/orolo/bnZwg/

$('.remove_new').click(function() {
    $(this).parent().parent().remove();
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文