将 onSelect 与 jQuery 的日期选择器结合使用的语法
我希望足够简单。当我点击 jQuery 的日期选择器中的日期时,我试图让 div 淡入淡出:
<!DOCTYPE html>
<html>
<head>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script type="text/javascript" src="../datepicker/jquery.ui.core.js"></script>
<script type="text/javascript" src="../datepicker/jquery.ui.widget.js"></script>
<script type="text/javascript" src="../datepicker/jquery.ui.datepicker.js"></script>
<script>
$(document).ready(function() {
$('#datepicker').datepicker();
$('#datepicker').datepicker({
onSelect: function(dateText, inst) {
$('#foo').fadeIn();
});
});
});
</script>
</head>
<body style="font-size:62.5%;">
<p>Choose a date: <input id="datepicker" type="text"></p>
<div id="foo">FOO</div>
</body>
</html>
Simple enough, I hope. I'm trying to get a div to fadeIn when I click on a date in jQuery's datepicker:
<!DOCTYPE html>
<html>
<head>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script type="text/javascript" src="../datepicker/jquery.ui.core.js"></script>
<script type="text/javascript" src="../datepicker/jquery.ui.widget.js"></script>
<script type="text/javascript" src="../datepicker/jquery.ui.datepicker.js"></script>
<script>
$(document).ready(function() {
$('#datepicker').datepicker();
$('#datepicker').datepicker({
onSelect: function(dateText, inst) {
$('#foo').fadeIn();
});
});
});
</script>
</head>
<body style="font-size:62.5%;">
<p>Choose a date: <input id="datepicker" type="text"></p>
<div id="foo">FOO</div>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
1. 您的代码有一个额外的括号和分号,请参阅下面代码的注释:
这是正确的代码:
2. 无需将
datepicker()
附加到两次同样的元素,您只需使用适当的参数分配一次,这就是为什么我删除了额外的$('#datepicker').datepicker()
。3. 您应该隐藏该元素,以便使其保持隐藏状态,直到您淡入为止。使用此 CSS:
检查此处演示 »
1. Your code has an extra parentheses and a semi-colon, see the comment on the code below:
This is the correct code:
2. There is no need to attach the
datepicker()
twice to the same element, you just assign it once, with the appropriate parameters, hence why I removed the extra$('#datepicker').datepicker()
.3. You should hide the element in order for it to remain hidden until you fade it in. Use this CSS:
Check a demo here »
你的javascript有错误,另一个问题是你不能fadeIn()一个可见的元素:你必须先隐藏它。
试试这个:
小提琴:http://jsfiddle.net/vH4HV/1/
You have errors on your javascript and another problem is that you can't fadeIn() an element which is visible: you have to hide it before.
Try this:
fiddle: http://jsfiddle.net/vH4HV/1/