当按下按钮从php获取json ajax数据时,点击表格标题(asc,dsc)时出现问题,这些数据来自构建我的表格的php。我使用函数sortresult按表标题排序表中的值。函数排序结果构建我的表。 我recive json数据成功。在获取json ajax数据后点击hedings时出现问题
如果我不使用按钮来显示数据(只是一个点亮的位更改代码),automaticaly让json用ajax和创建表,然后点击工作正常。没有使用按钮的问题是什么问题?
所以我有功能:
$(document).ready(function(){
$('#submit').click(function(event){
$('#headings th').click(function(){
$('#results').html("");
var id=$(this).attr('id');
var asc =(!$(this).attr('asc'));
$('#headings th').each(function() {
$(this).removeAttr('asc');
});
if(asc) $(this).attr('asc','asc');
sortResult(id, asc);
});
showResult();
});
});
功能sortResult:
function sortResult(prop, asc){
var val=null;
dataOut = dataOut.sort(function(a,b){
if(asc) return (a[prop] > b[prop]);
else return (b[prop] > a[prop]);
});
showResult();
}
功能showresult:
function showResult(){
var html='';
for (var i in dataOut){
html +='<tr>'
+'<td>'+dataOut[i].email+'</td>'
...
+'</tr>'
}
html+='</table>'
$('#results').html(html);
}
这几乎是在单击第一个元素之前,第二个点击处理程序将不可用,然后每次单击第一个元素时,都会添加更多的处理程序第二个。 – Barmar