0

我有一个带有高级选项的表格。高级选项位于 div(隐藏)中。当“搜索”输入框被键入时,我想使用向下滑动取消隐藏 div。这是代码(部分取自另一个来源:jQuery slideDown with forms):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
    <script src="http://api.jquery.com/resources/events.js"></script>
    <script type="text/javascript">
$("#searched").keypress(function(event) {
  if ( event.which == 13 ) {
     event.preventDefault();
   }
        $("#advanced").slideDown();

});
    </script>
</head>
<body>

<div id="content">
<form action="mycontrolleraddress" method="post" accept-charset="utf-8" name="search_form" id="search_form">

<input type="text" name="query" value="" placeholder="Search..." id="searched"/><br/>

<div id="advanced" style="display: none;">
    From: <input type="text" name="date_from" value="" id="datepicker" onchange="validateDate();" class="datefield"  /><br/>
    To: <input type="text" name="date_to" value="" id="datepicker2" onchange="validateDate();" class="datefield"  /> <br/>
</div>
<input type="submit" name="submit" value="Submit"  />

</div>

</body>
</html>
4

4 回答 4

1

把你的代码包装在里面$(document).ready(function(){});

于 2013-04-22T18:32:08.653 回答
0

在里面使用$(function() {});$(document).ready(function() {});

<script type="text/javascript">
    $(function() {
$("#searched").keypress(function(event) {
  if ( event.which == 13 ) {
     event.preventDefault();
   }
        $("#advanced").slideDown();

});
});
    </script>
于 2013-04-22T18:33:25.913 回答
0
$('#search_form').on('focus', '#searched', function(e){
    $('#advanced').slideDown();
})
于 2013-04-22T18:33:39.003 回答
0

解决方案是将您的 javascript 代码包装在其中:

$(document).ready(function(){
    // your code
});
于 2013-04-22T18:34:15.630 回答