我正在尝试使用jQuery删除表行,但我无法看到我出错了,因为我无法将其删除。
url: 'http://www.ncefl.org.uk/teams/hullunited/matches/2015/',
type: 'GET',
success: function(res) {
var extra = '#singlecolumn form #middle div table tr td i';
var trrem = $(res.responseText).find(extra).closest('tr').remove();
$('.inBx').html(res.responseText);
}
如上所述,我在表格行中找到<i>
元素,这是我想要完全删除的行。
<div class="six columns">
<h5 class="title03">Upcoming Matches</h5>
<div class="inBx">
<div class="loader"></div>
<div class="matchBx">
<div class="row">
<div class="four columns next_team">
</div>
<div class="four columns next_match">
</div>
<div class="four columns next_away_team">
</div>
</div>
</div>
<div class="row midTxt nxtmtchdate">
</div>
<table class="striped next_matches_block">
</table>
<p id="nextfa" class="fa"></p>
</div>
<a href="/fixtures-and-results" class="seebtn">See All Fixtures</a>
</div>
答案 0 :(得分:2)
这不会修改responseText
;它只会修改你创建的临时jQuery对象,然后扔掉。
如果要保留修改后的文档片段的副本,请执行以下操作:
var extra = '#singlecolumn form #middle div table tr td i';
var jres = $(res.responseText);
var trrem = jres.find(extra).closest('tr').remove();
$('.inBx').empty().append(jres);
var res = {
responseText: '<div> <div id="singlecolumn"> <form action=""> <div id="middle"> <div> <table>' +
'<tr> <td><i>italic</i></td> </tr> ' +
'<tr> <td>not</td> </tr> ' +
'</table> </div> </div> </form> </div> </div>'
}
var extra = '#singlecolumn form #middle div table tr td i';
var jres = $(res.responseText);
var trrem = jres.find(extra).closest('tr').remove();
$(document.body).append(jres);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>