【发布时间】:2015-05-30 10:26:15
【问题描述】:
如果输入文本已通过 Javascript 使用 .val() 更改,我需要触发一个事件,来自 jQuery API (https://api.jquery.com/change/):Note: Changing the value of an input element using JavaScript, using .val() for example, won't fire the event.
已经尝试过How can I trigger an onchange event manually?,但似乎不起作用...
这是我的代码:
<input type="text" id="datePrint" maxlength="10" size="6" disabled>
<img src="scripts/calendar/calendar.png" id="datePick" border="0" align="absmiddle" alt="Pick Date" width="40px" height="40px">
JS:需要激活日历事件
Calendar.setup({inputField:'datePrint',ifFormat:'%d/%m/%Y',button:'datePick',align:'T1',singleClick:true});
这是日历JS:
http://www.mediafire.com/view/yfrls2nx4m6ls52/calendarJs.txt
【问题讨论】:
-
要在
.change(function(){...});中执行代码块,调用$(document).change();就足够了 -
如果输入字段保持禁用状态,这里的解决方案应该适合您:stackoverflow.com/questions/16013024/…
-
或者在这里:stackoverflow.com/questions/19325938/… 可以说,这个问题与那些问题是重复的。
标签: javascript jquery onchange