我希望这不是浪费时间,但我真的一直试图解决这个问题。这是我的语法。我只想在点击一个“.remove-link”类的链接后删除父div“.number-row”。
提前致谢
<script>
$(document).ready(function(){
$(".remove-link").click(function() {
$(this).parent(".number-row").hide();
})
})
</script>
<div class="number-row" >
<div class="number-column">
<div class="label-row">
Select Country:
</div>
<div class="input-row">
<select>
<option>1</option>
<option>2</option>
</select>
</div>
<div class="label-row">
Select Toll Free or City:
</div>
<div class="input-row">
<select>
<option>1</option>
<option>2</option>
</select>
</div>
<div class="label-row">
Select Your Number:
</div>
<div class="input-row">
<select>
<option>1</option>
<option>2</option>
</select>
</div>
</div>
<div class="number-column">
<div class="label-row">
Select Country:
</div>
<div class="input-row">
<select>
<option>1</option>
<option>2</option>
</select>
</div>
<div class="label-row">
Enter Number to Forward to:
</div>
<div class="input-row">
<input type="text" name="forward_number" id="forward_number" />
</div>
<div class="number-row-options">
<a class="save-link" href="#">Save</a>
<a class="remove-link" href="#">Remove</a>
</div>
</div>
</div>
答案 0 :(得分:7)
$(document).ready(function(){
$(".remove-link").click(function() {
$(this).parents(".number-row").eq(0).hide();
})
})
答案 1 :(得分:2)
应该这样做......
$(document).ready(function(){
$(".remove-link").click(function() {
$(this).parent().parent().parent().hide();
})
})
请注意,这不是您要求的删除;它只是隐藏它。您可以使用remove()
代替hide()
将其从DOM中删除。