.children()を使用してdiv内のテーブルを空にしようとすると、ajaxの新しい結果が追加されますが、トラバースが機能しません。私のtrは、別の関数でajaxを使用して動的に作成されるため、クリックの成功ajax内で関数を呼び出して、リクエストを再度リロードし、divを再度リロードするようにします。plssはみんなを助けます。
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>
ajax:
$('.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;
});
}
});
}
load_elementary();