jQuery 日期选择器使用 getXMLHTTP()
我想获取日期选择器值来更改所选选项值。所以我必须使用像 onchange 这样的事件来更改下一个值。但 jQuery 不支持 onchange。我该怎么做?
function gettime(str) {
var strURL="/Doctor/booking/gettime.jsp?datepicker="+str;
var req = getXMLHTTP();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
document.getElementById('datepicker').innerHTML=req.responseText;
} else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
<b>Date: <input type="text" id="datepicker" name="datepicker" readonly="true" change="gettime(this.value)"></b>
jQuery:
<script>
$(document).ready(function() {
$(function() {
$( "#datepicker" ).datepicker({dateFormat: 'yy-mm-dd',
maxDate: '+1m',
minDate: 'Now',
beforeShowDay: noSundays
});
});
});
function noSundays(a) { a=a.getDay(); return[a>0&&a<7,""]; }
I want to get the datepicker value to change the selected option value. So I must use an event like onchange to change the next value. But jQuery does not support onchange. How can I do this?
function gettime(str) {
var strURL="/Doctor/booking/gettime.jsp?datepicker="+str;
var req = getXMLHTTP();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
document.getElementById('datepicker').innerHTML=req.responseText;
} else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
<b>Date: <input type="text" id="datepicker" name="datepicker" readonly="true" change="gettime(this.value)"></b>
jQuery:
<script>
$(document).ready(function() {
$(function() {
$( "#datepicker" ).datepicker({dateFormat: 'yy-mm-dd',
maxDate: '+1m',
minDate: 'Now',
beforeShowDay: noSundays
});
});
});
function noSundays(a) { a=a.getDay(); return[a>0&&a<7,""]; }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的页面中包含 jquery 并按照 1999 年 Microsoft 首次在 Internet Explorer 5 中引入 XMLHTTP ActiveX 对象时的方式执行 AJAX?我简直不敢相信自己的眼睛。
因此,让我们利用我们正在使用的框架所提供的功能来实现这一点,并摆脱这个
gettime
函数:然后:
You have jquery included in your page and do AJAX the way we did it in 1999 when Microsoft first introduced the XMLHTTP ActiveX object in Internet Explorer 5? I cannot believe my eyes.
So, let's do this by taking advantage of what the framework we are using has to offer to us and get rid of this
gettime
function:and then: