我试图使用 .children() 清空 div 中的表,然后附加 ajax 的新结果,但我的遍历不起作用。我的 tr 是使用带有另一个函数的 ajax 动态创建的,以便我在 click 的成功 ajax 中调用该函数以再次重新加载请求,使其像再次重新加载 div 一样。请帮助伙计们..
html
<div id="curr-elem">
<div class="box-header">
<h3>Elementary Subject</h3>
</div>
<div id="curr-elem-content">
<table id="curr-elem-tble">
<tr>
<td>
<lable>Subject:<input type="text" readonly="readonly" value="a" rel="1" name="subject[0]"></lable>
</td>
<td>
<input id="activate[0]" class="button active modal2 inactiveButton" type="button" disabled="disabled" value="Apply" name="active" rel="#loading-window">
<input id="inactivate[0]" class="button inactive modal2 " type="button" value="Remove from list" name="active" rel="#loading-window">
</td>
</tr>
<tr>
<td>
<lable>Subject:<input type="text" readonly="readonly" value="ssssss" rel="8" name="subject[1]"></lable>
</td>
<td>
<input id="activate[1]" class="button active modal2 inactiveButton" type="button" disabled="disabled" value="Apply" name="active" rel="#loading-window">
<input id="inactivate[1]" class="button inactive modal2 " type="button" value="Remove from list" name="active" rel="#loading-window">
</td>
</tr>
<tr>
<td>
<lable>Subject:<input type="text" readonly="readonly" value="alvin" rel="9" name="subject[2]"></lable>
</td>
<td>
<input id="activate[2]" class="button active modal2 inactiveButton" type="button" disabled="disabled" value="Apply" name="active" rel="#loading-window">
<input id="inactivate[2]" class="button inactive modal2 " type="button" value="Remove from list" name="active" rel="#loading-window">
</td>
</tr>
<tr>
<td>
<lable>Subject:<input type="text" readonly="readonly" value="ronniel" rel="10" name="subject[3]"></lable>
</td>
<td>
<input id="activate[3]" class="button active modal2 inactiveButton" type="button" disabled="disabled" value="Apply" name="active" rel="#loading-window">
<input id="inactivate[3]" class="button inactive modal2 " type="button" value="Remove from list" name="active" rel="#loading-window">
</td>
</tr>
</table>
</div>
</div>
阿贾克斯:
$('.active').live('click',function (){
var prev = $(this).parent().prev().find('input[type=text]');
var valText = $(prev).val();
var relVal = $(this).parent().prev().find('input[type=text]').attr('rel');
var div = $(this).parent().parent().parent().parent().parent().attr('id');
$.ajax({
type:'POST',
url:'add_subject.php',
dataType:'json',
data:{'func_numbr':'7','subjct_name':valText,'subjct_id':relVal},
success:function (data){
$('#mask2').hide();
$('#loading-window').hide();
$("[id*="+div+"]").children().children().find("table").html("");
load_elementary();
}
});
});
function load_elementary(){
var html;
$.ajax({
type:'POST',
url:'add_subject.php',
dataType:'json',
data:{'func_numbr':'2'},
success:function (data){
var activator;
var disabler;
var counter_sub = 0 ;
$.each(data, function(i, item) {
if(data[i].subj_status == "0"){
classToAddInactve = "inactiveButton";
DisableInactve = "disabled=\"disabled\""
classToAddActve = "";
DisableActve = ""
}
else{
classToAddInactve = ""
DisableInactve = ""
classToAddActve = "inactiveButton";
DisableActve = "disabled=\"disabled\""
}
html = "<tr>";
html += "<td><lable>Subject: </label><input type='text' name='subject["+counter_sub+"]' rel='"+data[i].subj_id+"' value='"+data[i].subj_name+"' readonly='readonly'></td>";
html += "<td><input type='button' rel='#loading-window' id='activate["+counter_sub+"]' name='active' class='button active modal2 "+classToAddActve+"' value='Apply' "+DisableActve+"> ";
html += "<input type='button' rel='#loading-window' id='inactivate["+counter_sub+"]' name='active' class='button inactive modal2 "+classToAddInactve+"' value='Remove from list' "+DisableInactve+"></td>";
html += "</tr>";
$('#curr-elem-tble').append(html);
counter_sub = counter_sub +1;
});
}
});
}
加载元素();