jQuery slideDown with forms

笑着哭i 提交于 2019-12-08 06:19:52

问题


why the following code doesn't work? Under Opera it show just a black line for a second where the div should be, Under IE it shows div for 1 second, under FF nothing happens.

function showAdvanced(){
$("#advanced").slideDown("slow");
};

<div id="content">
  <form action="mycontrolleraddress" method="post" accept-charset="utf-8" name="search_form" id="search_form">
  <input type="text" name="query" value="" style="width:300px;font-size:18pt;border-color:#0080FF;border-width:2px;border-style:solid;background-color:#F2F2F2;"  />  
  <a href="" onclick="showAdvanced();" style="font-size:8pt;font-color:blue;">Advanced options</a>
  <br/>
  <div id="advanced" style="position:relative;height:400px;">From: 
    <input type="text" name="date_from" value="" id="datepicker" onchange="validateDate();" class="datefield"  /> To: 
    <input type="text" name="date_to" value="" id="datepicker2" onchange="validateDate();" class="datefield"  /> 
    <input type="text" name="limit" value="Results limit"  />
  </div>
  <input type="submit" name="submit" value="Szukaj"  />           
</div>

It's basically a textbox for search query, and I want advanced options (two data pickers and textbox) to appear after clicking a link.


回答1:


Is your script inside <script> tags, in <head>? Make sure it looks something like this: http://jsfiddle.net/bJQVa/. Note that I also set #advanced to be hidden by default.

NOTE: I also added a # for the href and a return false in the function.




回答2:


<!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 type="text/javascript">

        console.log('script loaded');

        function showAdvanced() {
            console.log('showAdvanced() executed');
            $("#advanced").slideDown("slow");
        };

        $(document).ready(function(){
            console.log('document is ready');
        });

    </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=""/><br/>

<a href="#" onclick="showAdvanced();" style="font-size:8pt;font-color:blue;">Advanced options</a><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/>
    <input type="text" name="limit" value="Results limit"  />
</div>
<input type="submit" name="submit" value="Szukaj"  />

</div>

</body>
</html>

Working for me. Next time try to format your code better, so it will be more readable.



来源:https://stackoverflow.com/questions/6526725/jquery-slidedown-with-forms

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!