首页 新闻 会员 周边

JQuery动态生成的表格不能使用TableSorter

0
悬赏园豆:5 [已关闭问题]

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<style>
th.headerSortUp {
     /*background-image: url(../img/small_asc.gif);*/
     background-color: #3399FF;
 }
th.headerSortDown {
     /*background-image: url(../img/small_desc.gif);*/
     background-color: #3399FF;
 }
th.header {
     /*background-image: url(../img/small.gif);*/
     cursor: pointer;
     font-weight: bold;
     background-repeat: no-repeat;
     background-position: center left;
     padding-left: 20px;
     border-right: 1px solid #dad9c7;
     margin-left: -1px;
 }
</style>


<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery.tablesorter.js"></script>
<script type="text/javascript">
function User(userName,userEmail){
this.userName="";
this.userEmail="";
};
$(document).ready(function(){
  
});
function getDataFromServer()
{
    var sendData={"data":"tableData"};
    $.post("GetData.aspx",sendData,function(response){////使用post传递数据,参数:url,数据,返回时处理的函数
                    var users=eval("("+response.toString()+")");
                    createTableRows(users);
                    $("#myTable").tablesorter();
                });
                $("#myTable").tablesorter();
}
function deleteRow(index)
{
    $(index).remove();
}
function createTableRows(userList)
{
    $("#content #mytable tbody tr").remove();
    var bodytemp=$("#mytable tbody");
    for(var i=0;i<userList.length;i++)
    {
        bodytemp.append("<tr id='tr"+i+"'><td>"+userList[i].userName+"</td><td>"+userList[i].userEmail+"</td><td><input type='submit' value='delete' onclick=\"deleteRow('#tr"+i+"')\"></td></tr>");
       
    }
}
</script>
</head>

<body>
<input type="button" id="getData" value="GetData" onclick="getDataFromServer()">
<div id="content">
    <table id='mytable'><thead><tr><th>Name</th><th>Email</th><th>action</th></tr></thead><tbody></tbody></table>
</div>
</body>
</html>
上面是页面代码,下面是返回数据的asp.net页面,数据在response中返回,故该sapx页面为一个空页面,一防止response中含有页面数据
using System;
using Newtonsoft.Json;

public partial class GetData : System.Web.UI.Page
{
    public class User
    {
        public String userName;
        public String userEmail;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        byte[] param=new byte[Request.InputStream.Length];
        Request.InputStream.Read(param, 0, param.Length);
        string jsonstr = System.Text.Encoding.Default.GetString(param);
        String result = "";
        User[] users=new User[2];
        User temp = new User();
        User temp2=new User();
        temp.userName = "lee";
        temp.userEmail = "lee@lee.com";
        temp2.userName = "lee";
        temp2.userEmail = "lee@lee.org";
        users[0] = temp;
        users[1] = temp2;
        Object obj = JsonConvert.SerializeObject(users);
        if(obj!=null)
        {
            result = obj.ToString();
            Response.Write(result);
        }
    }
}
问题是tabelsorter不能使用,求高手帮忙解决,3ks!

舞动的梦的主页 舞动的梦 | 初学一级 | 园豆:195
提问于:2009-08-14 16:04
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册