为什么以下代码不起作用?在Opera下它只显示一个黑色的行,div应该是,在IE下它显示div 1秒,在FF下没有任何反应。
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>
它基本上是搜索查询的文本框,我希望在点击链接后显示高级选项(两个数据选择器和文本框)。
答案 0 :(得分:0)
您的脚本位于<script>
内的<head>
标记内吗?确保它看起来像这样:http://jsfiddle.net/bJQVa/。请注意,我还默认将#advanced设置为隐藏。
注意:我还为href添加了#,并在函数中返回false。
答案 1 :(得分:0)
<!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>
为我工作。下次尝试更好地格式化代码,以便更具可读性。