[英]jquery datepicker onSelect won't call custom function in Internet Explorer
I have a datepicker initialized such as: 我有一个初始化的日期选择器,例如:
$("#startDate").datepicker({ onSelect: dateChanged });
This works in conjunction with the input: 这与输入结合使用:
<input type="text" id="startDate" value="" class="dateField"/>
that is in a table for a search over a jquery dataTable. 在用于搜索jquery dataTable的表中。
This works great in chrome, but fails to work in IE. 这在chrome中效果很好,但在IE中无法正常工作。 My goal is to have today's data populate the dataTable
then when the start date changes to a previous date the onSelect
should call the dateChanged
function. 我的目标是让今天的数据填充到dataTable
然后当开始日期更改为上一个日期时, onSelect
应调用dateChanged
函数。 The dateChanged
function is responsible for querying the database again but with an earlier date. dateChanged
函数负责再次查询数据库,但日期更早。
In IE what happens is that when you select the text box for the date the calendar come up(good). 在IE中,发生的情况是,当您选择日历出现日期的文本框时(良好)。 When you select the desired date the calendar does not go away. 当您选择所需的日期时,日历不会消失。
I have had a test function call with no problems. 我进行了一个测试函数调用,没有问题。 The difference is that the test function just has an alert and the dateChanged
function has variables initialized and query calls. 区别在于测试功能仅具有警报,而dateChanged
功能具有已初始化的变量和查询调用。 It seems to work fine until I create a variable of any sort. 在创建任何类型的变量之前,它似乎都可以正常工作。
Any suggestions would be helpful. 任何的意见都将会有帮助。
UPDATE 更新
Here is a little more of the function I am trying to call: 这里是我尝试调用的函数的更多内容:
function dateChanged(){
var StartTime = startDate.value;
var EndTime = endDate.value;
alert("hello");
var cmecProx2 = new cmec();
...
}
Most of the code I have I cannot share due to it being for a company I work for but from the code above I am not getting to the alert statement. 我拥有的大多数代码都无法共享,因为这是我所工作的公司的代码,但是从上面的代码中我并不会进入警报声明。
Some browsers don't fire events in a timely fashion. 某些浏览器无法及时触发事件。 So what works well in FF/Chrome may not work at all in IE. 因此,在FF / Chrome中行之有效的方法在IE中可能根本不起作用。 I've had good success in these situations by wrapping the event code in a timeout. 通过在超时中包装事件代码,我在这些情况下取得了成功。
$("#startDate").datepicker({ onSelect: function(){setTimeout(dateChanged, 500);} });
This will delay the firing of dateChanged()
by half a second, and--if timing is the problem--would give IE enough time to realize the onSelect
event has fired. 这将延迟dateChanged()
的触发半秒,并且-如果出现计时问题-将为IE提供足够的时间来实现onSelect
事件已触发。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.