我正在尝试从数据库导入记录并将类应用于这些记录。记录被正确导入,但我丢失了类引用和导入文本的css。我尝试重置属性,但它不需要。 请注意,我已经注释掉了从数据库导入文本的行:
document.getElementById("tablesorter-demo").innerHTML=xmlhttp.responseText;
当我这样做时,现有的html文本正常工作。如何导入文本并将类(即应用tablesorter类)和css应用于导入的文本?
getElement.setAttribute("class", "tablesorter");
谢谢你的时间!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us">
<head>
<title>Tablesorter</title>
<link rel="stylesheet" href="styles.css" type="text/css" media="print, projection, screen" />
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"> </script>
<script type="text/javascript" src="__jquery.tablesorter.min.js"></script>
<script type="text/javascript">
$(function() {
$("#tablesorter-demo").tablesorter({sortList:[[0,0],[2,1]], widgets: ['zebra']});
$("#options").tablesorter({sortList: [[0,0]], headers: { 3:{sorter: false}, 4:{sorter: false}}});
});
window.onload = function() {
if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}else {// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
//console.log(xmlhttp.responseText);
//document.getElementById("tablesorter-demo").innerHTML=xmlhttp.responseText;
var getElement = document.getElementById("tablesorter-demo")
getElement.setAttribute("class", "tablesorter");
getElement.setAttribute("border", "1");
}
}
xmlhttp.open("GET","createTableList.php",true);
xmlhttp.send();
}
</script>
</head>
<body>
<div id="main">
<table id='tablesorter-demo' >
<thead>
<tr>
<th>Login ID</th>
<th>First Name</th>
<th>Last Name</th>
</tr>
</thead>
<tbody>
<tr>
<td>120</td>
<td>Jenny</td>
<td>Jones</td>
</tr>
<tr>
<td>121</td>
<td>Billy</td>
<td>Bob</td>
</tr>
</tbody>
</table>
</div>
</body>
class</html>