JQuery动态添加表格tr td


功能:ajax获取后台返回数据给table动态添加tr/td


html:


ajax:
var year = $('#year').val();//下拉框数据
var province= $('#province').val();//下拉框数据
$('table tbody').html('');
$.ajax({
    url:"/Plan/sendJson.html",
    type:"get",
    data:{
         'year':year,
         'province':province
    },
    datatype:'json',
    success:function(data){
         switch(data.msg)
         {
                case '0':
                        $('table tbody').prepend('暂无数据');break;
                case '1':
                       $.each(data.data,function(i,n){
var $tr = $(""+
""+n.year+""+
""+n.province+""+
"");
var $table = $('table tbody');
$table.append($tr);
});
}
}
})

php:

$year = I('get.year');
$province = I('get.province');

$condition = array();
$year && $condition = array('eq',$year);
$province && $condition = array('eq',$province);
$dataList = M('Plan')->where($condition)->select();
if(false != $dataList){
    $data['msg'] = '1';
    $data['data'] = $dataList;
    echo json_encode($data);
    exit;
}else{
    $data['msg'] = '0';
    $data['data'] = '';
    echo json_encode($data);
    exit;
}


一个每天吃超过十块钱盖饭都要思索半天

却始终心系宇宙从哪来到哪去的普普通程序员

2017.9.27

你可能感兴趣的:(JQuery)