jquery datepicker 点击日期控件不会自动更新input的值
<script type="text/javascript"> $(function(){ $( ".datepicker").datepicker({dateFormat: 'yy-mm-dd'}); //$.iniNav("engagement"); });</script>
最終效果如圖所示: 但是放在engagement頁(yè)面里的時(shí)候,點(diǎn)擊選擇每天的時(shí)候,不能自動(dòng)更新到input里面去。單步調(diào)試代碼,發(fā)現(xiàn),input能夠定位到,而且代碼執(zhí)行的過程中有獲取到點(diǎn)擊的按鈕對(duì)應(yīng)的當(dāng)天的日期。 在jqueryUI里對(duì)應(yīng)的代碼塊兒如下: /* Update the input field with the selected date. */_selectDate: function(id, dateStr) {var target = $(id);var inst = this._getInst(target[0]);dateStr = (dateStr != null ? dateStr : this._formatDate(inst));if (inst.input)inst.input.val(dateStr);this._updateAlternate(inst);var onSelect = this._get(inst, 'onSelect');if (onSelect)onSelect.apply((inst.input ? inst.input[0] : null), [dateStr, inst]); // trigger custom callbackelse if (inst.input)inst.input.trigger('change'); // fire the change eventif (inst.inline)this._updateDatepicker(inst);else {this._hideDatepicker();this._lastInput = inst.input[0];if (typeof(inst.input[0]) != 'object')inst.input.focus(); // restore focusthis._lastInput = null;}},
關(guān)鍵的賦值代碼在 ?inst.input.val(dateStr);而且這句執(zhí)行結(jié)束的時(shí)候,input的value的確被改掉了成為最新的,但是input里看不到任何效果。
原因在哪? 我只能查看返回的input的context哪里不同,進(jìn)行對(duì)比: 能正常顯示點(diǎn)擊的最新日期的input:? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
區(qū)別:
baseURL:
jQuery183017439375561662018
后來發(fā)現(xiàn),其實(shí)這個(gè)問題是由我的代碼自己造成的,每次clone過去的代碼是包含了datepicker的事件的,也就是說如果我在創(chuàng)建新的graphBox,(執(zhí)行g(shù)raphBox.prototype._createBox以后)再去綁定datepicker事件就不會(huì)出現(xiàn)這樣的情況了。。。改成現(xiàn)在這樣:
graphBox = function(opt){this.content_wrapper = opt.content_wrapper;this.demo_graph_body = opt.demo_graph_body;this.bookmarkID = opt.bookmarkID;this._createBox(); this._createDatePicker(); this._handleActions(); this._drawChart();}其中this._createDatePicker(); ? 的代碼如下:
graphBox.prototype._createDatePicker = function(){$(this.graph_body).find(".datepicker").datepicker({dateFormat: 'yy-mm-dd'}); }這里只設(shè)置了datepicker的dateFormat: 'yy-mm-dd',未做其他任何設(shè)定。
通過測(cè)試,ok了。。。。
轉(zhuǎn)載于:https://www.cnblogs.com/xiami303/archive/2012/12/21/2828416.html
總結(jié)
以上是生活随笔為你收集整理的jquery datepicker 点击日期控件不会自动更新input的值的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 助人快乐:笔记本连网
- 下一篇: atmega8 例程:USART串口通信