我正在从一个php mysql服务器提取搜索数据,并希望在表格中显示它。这是我到目前为止编写的代码。
search_member.php已经测试过了,可以正常运行。如您所见,我试图将该数据的innerHTML插入到id为“search”的div中。我认为这不起作用,因为div无法放在表格中。我已经使用了js insertRow和jquery,但是由于每次输入的数据都不同,js insertRow和jquery仅会不断添加行,最终导致500行。我只需要一种方法,在我的表格中最后一个</tr>之后插入从search_member.php返回的数据。
感谢您的帮助。
function getrows(page, parameters, element_id)
{
if (parameters.length==0)
{
document.getElementById(element_id).innerHTML="";
return;
}
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById(element_id).innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET",page + "?" + parameters,true);
xmlhttp.send();
}
<table style="text-align: left; width: 0%; margin-left: auto; margin-right: auto;" border="1" cellpadding="2" cellspacing="0">
<tbody>
<tr style="background-color:#d0e4fe;">
<td>First Name:</td>
<td>Last Name:</td>
<td>Date of Birth:</td>
<td>Phone Number:</td>
<td>Action:</td>
</tr>
<tr>
<td><input onkeyup="getrows('actions/search_member.php', 'first_name=' + getvalue('first_name') + '&last_name=' + getvalue('last_name') + '&birth_date=' + getvalue('birth_date') + '&home_phone=' + getvalue('home_phone'), 'search');" name="first_name"></td>
<td><input onkeyup="getrows('actions/search_member.php', 'first_name=' + getvalue('first_name') + '&last_name=' + getvalue('last_name') + '&birth_date=' + getvalue('birth_date') + '&home_phone=' + getvalue('home_phone'), 'search');" name="last_name"></td>
<td><input onkeyup="getrows('actions/search_member.php', 'first_name=' + getvalue('first_name') + '&last_name=' + getvalue('last_name') + '&birth_date=' + getvalue('birth_date') + '&home_phone=' + getvalue('home_phone'), 'search');" name="birth_date"></td>
<td><input onkeyup="getrows('actions/search_member.php', 'first_name=' + getvalue('first_name') + '&last_name=' + getvalue('last_name') + '&birth_date=' + getvalue('birth_date') + '&home_phone=' + getvalue('home_phone'), 'search');" name="home_phone"></td>
<td></td>
</tr>
<div id="search"></div>
</tbody>
search_member.php会根据输入的内容以以下格式返回5个成员的列表:
<tr>
<td>data</td>
<td>data</td>
<td>data</td>
<td>data</td>
<td>data</td>
</tr>
search_member.php已经测试过了,可以正常运行。如您所见,我试图将该数据的innerHTML插入到id为“search”的div中。我认为这不起作用,因为div无法放在表格中。我已经使用了js insertRow和jquery,但是由于每次输入的数据都不同,js insertRow和jquery仅会不断添加行,最终导致500行。我只需要一种方法,在我的表格中最后一个</tr>之后插入从search_member.php返回的数据。
感谢您的帮助。
<div id="search">
替换成<tbody id="search">
? - biziclop