jquery datepicker onselect 的问题
遵循 jquery 网站上的基本 onSelect 规范,我尝试了以下代码:
<!DOCTYPE html>
<html>
<head>
<link type="text/css" href="http://jqueryui.com/latest/themes/base/ui.all.css" rel="stylesheet" />
<script type="text/javascript" src="http://jqueryui.com/latest/jquery-1.3.2.js"></script>
<script type="text/javascript" src="http://jqueryui.com/latest/ui/ui.core.js"></script>
<script type="text/javascript" src="http://jqueryui.com/latest/ui/ui.datepicker.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#datepicker").datepicker();
$('#datepicker').datepicker({
onSelect: function(dateText, inst) { alert("Working"); }
});
});
</script>
</head>
<body style="font-size:62.5%;">
<div type="text" id="datepicker"></div>
</body>
</html>
但无法让它工作! 最初一直试图让更复杂的事情发挥作用,但 onSelect 不起作用,所以我回到基础知识,但仍然不起作用,有人知道我做错了什么吗?
Following the basic onSelect spec on the jquery site I tried the following code:
<!DOCTYPE html>
<html>
<head>
<link type="text/css" href="http://jqueryui.com/latest/themes/base/ui.all.css" rel="stylesheet" />
<script type="text/javascript" src="http://jqueryui.com/latest/jquery-1.3.2.js"></script>
<script type="text/javascript" src="http://jqueryui.com/latest/ui/ui.core.js"></script>
<script type="text/javascript" src="http://jqueryui.com/latest/ui/ui.datepicker.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#datepicker").datepicker();
$('#datepicker').datepicker({
onSelect: function(dateText, inst) { alert("Working"); }
});
});
</script>
</head>
<body style="font-size:62.5%;">
<div type="text" id="datepicker"></div>
</body>
</html>
And can't get it to work!
Originally been trying to get a more complicated thing to work but the onSelect was just not working so I went back to basics and still don't work, anyone any idea what I'm doing wrong??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您没有正确使用 api。 不要觉得不好,一开始会很混乱。
这两行都告诉日期选择器小部件在元素上初始化日期选择器:
您可以删除第一行,因为它除了阻止第二行产生任何影响之外没有做任何事情。
如果您想在初始化小部件后更改其中一个选项的值,那么您需要使用此 api:
或者,您可以使用 jQuery 的
bind
函数附加一个处理程序:You're not using the api correctly. Don't take it bad, it's confusing at first.
Both of these lines are telling the datepicker widget to initialize a datepicker on an element:
You could remove the first one since it's not doing anything except preventing the second one from having any effect.
If you want to change the value of one of the options after you've already initialized the widget then you would need to use this api:
Or alternatively, you could attach a handler using jQuery's
bind
function:选择日期时此代码必须有效吗:
Must this code work when select a date:
您可以尝试删除该行上方的第二个
$("#datepicker").datepicker()
,留下:You might try removing the second
$("#datepicker").datepicker()
immediately above that line, leaving:jQuery datepicker 的 onSelect 有时不起作用,但您可以通过调用
input
类型的onchange
事件上的方法来绕过它。将此
changeDate()
方法调用为 -jQuery datepicker's onSelect doesn't work sometimes but you can just bypass it by calling a method on
onchange
event of yourinput
type.Call this
changeDate()
method as-