单击删除时需要删除整行
<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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
假设您在要删除的行的
内有一个按钮、链接或其他内容,您可以执行类似以下代码的操作。
$(this).closest('tr').remove()
——最接近的将在 DOM 中向上查找tr
元素。如果您想快速修复代码,请尝试onclick="$(this).closest('tr').remove();"
HTML
jQuery
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.$(this).closest('tr').remove()
-- closest will travel up the DOM finding thetr
element. If you wanted a quick fix for your code, tryonclick="$(this).closest('tr').remove();"
HTML
jQuery
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.我在该代码中看到的唯一直接错误是:
...最后有一个额外的
);"
。它应该是:它位于
第一个两个元素。
The only immediate error that I can see in that code is this:
...you have an extra
);"
at the end. It should be:It's on
the firstboth<a>
elements.您的代码中有一些语法错误,让我们只看一下删除链接
这可能应该是
最好按照这样的方式做一些事情
这样您就不必依赖 DOM 的稳定性并且它应该可以工作,我尝试在 JsFiddle 中测试它,但代码中的某些内容与 JsFiddle 混淆,并且它无法正确导入 jQuery。
将来,如果您很好地格式化代码并且可以提供简化的案例,您可能会更快地得到答案。
You have some syntax errors in your code, let's look at just the removal link
This should probably be
It's probably better to do something along the lines of
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.
http://jsfiddle.net/orolo/bnZwg/
http://jsfiddle.net/orolo/bnZwg/