我有一個DatePicker對象附加到一個文本框,該文本框按日期搜索&過濾器兩列(日期,文件名[帶有鏈接以打開實際.html文件])。這張桌子只有唯一的日期,所以當我搜索日期時,我只會得到一個結果。DatePicker +搜索表格中的文本框
我的問題是:如何使datepicker/searchbox過濾出表格,然後查看是否有結果,如果存在;然後直接打開文件,而不是讓用戶單擊文件名來打開它。如果沒有搜索日期的文件,則發出警報消息或其他內容。
下面的代碼:
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="ess_style.css">
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script type="text/javascript" src="jquery-latest.js"></script>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
</head>
<body>
<div id="esstable">
<input type="text" id="searchess" placeholder="ESS Date Search" style="float:left; margin:10; vertical-align:top"></input>
<table border="1" id="table_side2">
<tbody>
<tr>
<th>Date</th>
<th>ESS File</th>
</tr>
<tr>
<td>3/17/2014 </td>
<td> <a href="./file1.html"> file 1 </a> </td>
</tr>
<tr>
<td>3/22/2014 </td>
<td> <a href="./file2.html"> file 2 </a> </td>
</tr>
</tbody>
</table>
</div>
<script>
//datepicker
$(function() {
$("#searchess").datepicker({
dateFormat: "m/dd/yy",
onSelect: function() {
$("#searchess").trigger('keyup')
}
});
});
//search textbox
$("#searchess").keyup(function() {
if(typeof String.prototype.trim !== 'function') {
String.prototype.trim = function() {
return this.replace(/^\s+|\s+$/g, '');
}
}
var value = this.value.trim();
$("#esstable").find("tr").each(function(index) {
if (!index) return;
var id = $(this).find("td").first().text().trim();
$(this).toggle(id.indexOf(value) !== -1);
});
});
//script to populate table
$.getScript('index.js');
</script>
</body>
</html>
你已經有一個ONSELECT的日期選擇器定義 - 只需更新,要改變你需要做的放在location.href或任何其他。 – Dave
@Dave我不確定在那裏寫什麼代碼。你能舉個例子嗎? – DaPhunk
但是如果他們搜索不在表格中的日期會發生什麼?似乎搜索需要完成,然後才能確定是否找到任何結果,然後才能跳轉到頁面。 – jwatts1980