我想做一個搜索功能爲我的網站,我到達那裏;只是在選擇項目索引時遇到問題。jQuery的使用索引來查找一個元素
這是我ATM:
$(document).on('keyup', '.inputs input', function (event) {
var $inputVal = $(this).val();
var $inputListVal = $(this).closest('tr').find('input').index(this);
var $trList = $(this).parent().parent().parent().children();
$.each($trList, function(index) {
if (!$(this).hasClass('inputs') && !$(this).hasClass('first-item')) {
var tdList = $(this).children().index($inputListVal); <!-- This is whats not working ATM -->
console.log(tdList);
};
});
});
問題1:爲什麼它不工作任何想法?
問題2:我會怎麼做它的搜索一面呢?例如如果他們輸入pi
它會顯示所有以他們開頭的2個字母(餡餅,豬等)?
<tr class="inputs">
<th><input id="tick-all" type="checkbox" name="tick" value="download"></th>
<th><input class="small-input" type="text" name="box_number"></th>
<th><input class="md-input" type="text" name="client_name"></th>
<th><input class="md-input" type="text" name="make"></th>
<th><input class="small-input" type="text" name="qty"></th>
<th><input class="big-input" type="text" name="descnption"></th>
<th><input class="small-input" type="text" name="width"></th>
<th><input class="small-input" type="text" name="depth"></th>
<th><input class="small-input" type="text" name="height"></th>
<th><input class="md-input" type="text" name="colour"></th>
<th><input class="md-input" type="text" name="order_number"></th>
<th><input class="md-input" type="text" name="quality"></th>
<th><input class="big-input" type="text" name="picture"></th>
<th><input class="small-input" type="text" name="Order"></th>
</tr>
<?php
require_once('connent.php');
$sql = "SELECT * FROM client_info";
$result = mysqli_query($conn, $sql);
while ($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td><input type='checkbox' name='download-tick' value='download'></td>";
echo "<td>".($row['Box'])."</td>";
echo "<td>".($row['Client'])."</td>";
echo "<td>".($row['Make'])."</td>";
echo "<td>".($row['Descnption'])."</td>";
echo "<td>".($row['Width'])."</td>";
echo "<td>".($row['Depth'])."</td>";
echo "<td>".($row['Height'])."</td>";
echo "<td>".($row['Colour'])."</td>";
echo "<td>".($row['OrderNo'])."</td>";
echo "<td>".($row['Quality'])."</td>";
echo "<td>".($row['Picture'])."</td>";
echo "<td>".($row['Order'])."</td>";
echo "<td>23<br><input class='small-input' type='text' name='Order'></td>";
echo "</tr>";
}
//echo $count = mysqli_num_rows($result);
?>
請添加到您的html也讓我們可以檢查 –
用了HTML的細節也將難以重現該問題,請你加入Plunker –