单击按钮时显示表格 - Jquery/javascript
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20645164/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Display the table when click the button - Jquery/javascript
提问by user2848031
Please advise how to achieve that hide the html innter table when page loading and click the search button, table will display with results only.I don't want to show the empty table.Please see the below code which i have tried.
请告知如何实现在页面加载时隐藏 html 内部表格并单击搜索按钮,表格将仅显示结果。我不想显示空表格。请参阅我尝试过的以下代码。
But sure, after click the button page is getting refresh.
但是可以肯定的是,单击按钮后页面正在刷新。
$(document).ready(function() {
$("#historylist").hide();
$("#historysearch").click(function() {
$("#historylist").show();
});
// }
});
<table id="searchTbl" width="800" >
<tr>
<td valign="top">Release No</td>
<td valign="top">
<input type="text" name="releaseNo" value="" style="width:200" />
</td>
<td valign="top"><input type="button" value="Search" onClick="commit()" style="width:80" id="historysearch"/></td>
</tr>
<br /><br />
<table border="1" cellpadding="2" cellspacing="0" id="historylist">
<tr>
<th><font size="-1">Header1</font></th>
<th><font size="-1">Header2</font></th>
<th><font size="-1">Header3</font></th>
<th><font size="-1">Header4</font></th>
<th><font size="-1">Header5</font></th>
</tr>
</table>
</table>
JavaScript:
JavaScript:
function commit(){
document.menu.cmd.value='search';
document.menu.submit();
}
When click the button it show the table and again hiding the table.
单击按钮时,它会显示表格并再次隐藏表格。
$(document).ready(function() {
$("#historylist").hide();
$("#historysearch").click(function(e) {
e.preventDefault();
$("#historylist").show();
commit(); // moved from the onClick attribute });
});
采纳答案by Blazemonger
$("#historysearch").click(function(e) {
e.preventDefault();
$("#historylist").show();
commit(); // moved from the onClick attribute
});