2013-12-17 96 views
0

请指教如何实现在页面加载时隐藏html innter表并单击搜索按钮,表将仅显示结果。我不想显示空table.Please看到下面的代码,我已经尝试过。单击按钮时显示表 - jquery/javascript

但肯定的是,点击按钮页后得到刷新。

$(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:

function commit(){ 

    document.menu.cmd.value='search'; 
    document.menu.submit();  
} 

当单击该按钮,它显示表,并再次隐藏表。

$(document).ready(function() { 
$("#historylist").hide(); 
$("#historysearch").click(function(e) { 
    e.preventDefault(); 
    $("#historylist").show(); 
    commit(); // moved from the onClick attribute }); 
}); 

回答

0
$("#historysearch").click(function(e) { 
    e.preventDefault(); 
    $("#historylist").show(); 
    commit(); // moved from the onClick attribute 
}); 

http://api.jquery.com/event.preventDefault/

+0

当单击该按钮,它显示表,并再次隐藏表。 ()# $(document).ready(function(){(“#historylist”)。hide(); $(“#historysearch”)。click(function(e){ e.preventDefault(); $ (“#historylist”)。show(); commit(); //从onClick属性移动 }); }); – user2848031