Firefox:"event"未在 jquery Datepicker 中公开



在jquery datepicker onSelect函数中,我试图使用event.target抓取选定的元素。在chrome中,event.target对我可用,但在Firefox中则不可用。 我看到的任何地方都告诉我,在Firefox中,你只需要将事件声明为参数,但它似乎不起作用。我在这里做错了什么?

onSelect: function (dateString) {
//first parameter is the dateString
(function(event){
console.log(event); //is undefined
})();        
}

不应该定义事件吗?

编辑:我试图完成的是确定选择了哪个元素并抓取文本。 $(event.target(.text(( 在 chrome 中工作,但不能在 Firefox 中工作

onSelect选项是日期选取器选项,而不是实际的event

在此处查看日期选取器文档:http://api.jqueryui.com/datepicker/#option-onSelect

如果需要活动的日期选取器实例,则需要传递第二个参数。
如果需要关联的输入字段,请使用this

你几乎总是可以在 jQueryUI 小部件回调中使用this来访问发生小部件事件的元素。

$( function() {
$( ".datepicker" ).datepicker({
onSelect:function(){
console.log('Datepicker id is:', this.id)
}
});
});
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

<p>Date 1: <input type="text" id="datepicker-1" class="datepicker"></p>
<p>Date 2: <input type="text" id="datepicker-2" class="datepicker"></p>

最新更新