【发布时间】:2011-07-13 10:52:13
【问题描述】:
我有一个下拉菜单,我有 jQuery change 函数。
我想根据确认对话框来实现所选项目的更改。
如果确认为真,我可以继续进行选定的更改,否则我将现有项目保持为选中状态并取消更改事件。
如何用 jQuery 实现这个?
jquery函数
$(function () {
$("#dropdown").change(function () {
var success = confirm('Are you sure want to change the Dropdown ????');
if (success == true) {
alert('Changed');
// do something
}
else {
alert('Not changed');
// Cancel the change event and keep the selected element
}
});
});
要记住的一件事 change 函数仅在所选项目更改后才会触发
所以最好考虑在onchange 上实现它——但它在 jquery 中不可用。有什么方法可以实现吗?
【问题讨论】:
-
这看起来比使用全局变量更好。 stackoverflow.com/a/3963959/47167
标签: javascript jquery