gpt4 book ai didi

javascript - 单击图标打开 jQuery UI Datepicker

转载 作者:行者123 更新时间:2023-12-03 12:42:56 26 4
gpt4 key购买 nike

在主干 View 中,我在 html 中有以下代码

<input type="text" id="fromDate" name="fromDate"/><a id="cal">
<img src="img/calendar.gif"></a>

在 View 的js文件中,我有以下代码:

define(['jquery', 'underscore', 'backbone', 'text!views/page1/page1.tpl'], function($, _, Backbone, tmpl_page1View) {

var page1View = Backbone.View.extend({
// Setting the view's template property using the Underscore template method
template: _.template(tmpl_page1View),
// View constructor
initialize: function() {
self = this;

},
// View Event Handlers
events: {
"click #page2": "clickedPage2",
"click #cal":"calClicked"
},
// Renders the view's template to the UI
render: function() {
this.$el.html(this.template({data: this.templateData}));
// Maintains chainability
return this;
},
clickedPage2:function(){
window.location.href = "#page2"
},
calClicked:function(){
$("#fromDate").datepicker({
showOn: "button",
buttonImage: "img/calendar.gif",
buttonImageOnly: true
});

}

});
return page1View;
});

在单击日历图标事件时,我想打开日期选择器,但它不起作用。你能帮我解决这个问题吗?谢谢。

最佳答案

您应该初始化日期选择器,例如在 render 方法中,日期选择器将在单击按钮时自动打开,因此您根本不需要 calClicked

var page1View = Backbone.View.extend({
// Setting the view's template property using the Underscore template method
template: _.template(tmpl_page1View),
// View constructor
initialize: function() {
self = this;

},
// View Event Handlers
events: {
"click #page2": "clickedPage2",
"click #cal":"calClicked"
},
// Renders the view's template to the UI
render: function() {
this.$el.html(this.template({data: this.templateData}));

// init datepicker
this.$("#fromDate").datepicker({
showOn: "button",
buttonImage: "img/calendar.gif",
buttonImageOnly: true
});


// Maintains chainability
return this;
},
clickedPage2:function(){
window.location.href = "#page2"
}

});
return page1View;
});

关于javascript - 单击图标打开 jQuery UI Datepicker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23466485/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com