这是我的搜索代码,它没有添加通知功能时工作正常。但是,一旦我添加“通知”功能,它不会使这个“搜索”功能的工作。请帮助当我添加通知功能时,我的搜索功能将不起作用
编辑:我添加了关于如何显示表格的数据,我有搜索功能的代码。
$(document).ready(function(){
$("#search").keyup(function(){
if($(this).val() != "")
{
$("#table tbody>tr").hide();
$("#table td:contains-ci('" + $(this).val() + "')").parent("tr").show();
}
else
{
$("#table tbody>tr").show();
}
});
});
$.extend($.expr[":"],
{
"contains-ci": function(elem, i, match, array)
{
return (elem.textContent || elem.innerText || $(elem).text() || "").toLowerCase().indexOf((match[3] || "").toLowerCase()) >= 0;
}
});
那么这就是它的输入
<input type="search" id="search" class = "search" name = "search" placeholder="Search...">
的HTML代码,那么这是我如何填充表在我的页面
<label id = "title">Manage Licenses</label><br/>
</div>
</div>
<div class="row" style = "padding-bottom : 20px;">
<?php
$qry = $con->prepare("SELECT * FROM tbllicense, tblrequests WHERE ExpirationDate < DATE_ADD(NOW(), INTERVAL 2 MONTH) AND
tblrequests.ID = Request_ID AND tblrequests.Status = 'accepted' ORDER BY ExpirationDate");
$qry->execute();
$rows = $qry->fetchAll(PDO::FETCH_ASSOC);
$expiredcount = 0;
?>
<table class = "table" id = "table">
<thead>
<th>Record ID</th>
<th>Name</th>
<th>Email</th>
<th>License Type</th>
<th>Expiration</th>
<th>Options</th>
<tbody>
<?php
foreach ($rows as $row) {
?>
<tr>
<td><?= $row["Request_ID"] ?></td>
<td><?= $row["txtFName"] . " " . $row["txtSurname"] ?></td>
<td><?= $row["txtEmail"] ?></td>
<td><?= $row["txtLicense"] ?></td>
<td><?= date("M d, Y", strtotime($row["ExpirationDate"])) ?></td>
<td><input type = "button" class = "btnAccept" value = "Renew" onclick = "renew(<?= $row["Request_ID"] ?>)"/></td>
</tr>
<?php
}
?>
</thead>
</tbody>
</table>
</div>
当我添加了该功能(代码通知)。搜索将无法正常工作,当我在搜索表单中输入一个输入时,结果将只是空白。
<li style = "float:right">
<div style = "float:right">
<?php
$qry = $con->prepare("SELECT * FROM tbllicense, tblrequests WHERE ExpirationDate < DATE_ADD(NOW(), INTERVAL 2 MONTH) AND
tblrequests.ID = Request_ID AND tblrequests.Status = 'accepted'
UNION
SELECT * FROM tblvisa, tblrequests WHERE ExpirationDate < DATE_ADD(NOW(), INTERVAL 2 MONTH) AND
tblrequests.ID = Request_ID AND tblrequests.Status = 'accepted' ORDER BY ExpirationDate"
);
$qry->execute();
$rows = $qry->fetchAll(PDO::FETCH_ASSOC);
if ($qry->rowCount()) {
echo '<img width=15 height=13 src="img/alert.png" />';
}
?>
</div>
<a href='#' id = "notificationLink" class = "notificationLink" title = "Notification"><img src="img/notification.png"
style = " position : relative; width : 15px; height : 13px;"/></a>
<div id="notificationContainer">
<div id="notificationTitle">Notifications</div>
<div id="notificationBody" class="scrollbar2">
<?php
$qry = $con->prepare("SELECT * FROM tbllicense, tblrequests WHERE ExpirationDate < DATE_ADD(NOW(), INTERVAL 2 MONTH) AND
tblrequests.ID = Request_ID AND tblrequests.Status = 'accepted' ORDER BY ExpirationDate");
$qry->execute();
$rows = $qry->fetchAll(PDO::FETCH_ASSOC);
$expiredcount = 0;
?>
<table class = "table" id = "table">
<thead>
<?php
foreach ($rows as $row) {
$expiredcount++;
?>
<tr>
<td><a href='_admin_business_license.php' style = "color: white;" class = "link">The Request <?= $row["Request_ID"] ?> is expired or about to expire on
<?= date("M d, Y", strtotime($row["ExpirationDate"])) ?> from the Business License</a></td>
</tr>
<?php
}
?>
<?php
$qry = $con->prepare("SELECT * FROM tblvisa, tblrequests WHERE ExpirationDate < DATE_ADD(NOW(), INTERVAL 2 MONTH) AND
tblrequests.ID = Request_ID AND tblrequests.Status = 'accepted' ORDER BY ExpirationDate");
$qry->execute();
$rows = $qry->fetchAll(PDO::FETCH_ASSOC);
$expiredcount1 = 0;
?>
<?php
foreach ($rows as $row) {
$expiredcount1++;
?>
<tr>
<td><a href='_admin_visa.php' style = "color: white" class = "link">The Request <?= $row["Request_ID"] ?> is expired or about to expire on
<?= date("M d, Y", strtotime($row["ExpirationDate"])) ?> from the Visa</a></td>
</tr>
<?php
}
?>
</thead>
</table>
</div>
<div id="notificationFooter"><a href="notification.php">See All</a></div>
</div>
</li>
运行你检查控制台错误? –
是的,我没有检查控制台错误,但我没有发现任何与它有关的错误。 – RufusWilde
只是运行你的代码,并检查你的页面源代码,有id“搜索”只有一次在你的HTML? –