I use jQueryUI's tabs and when a user changes a form in the tab, it promprts the user tha开发者_JS百科t a change has been made.
My question is, how do I revert the values before being changed when the user presses 'OK' on my confirm() prompt?
You'll have to keep track of what the values were before changing them... so something like this should work for you:
var oldValues = {};
$(function() {
$(":input").each(function() {
oldValues[$(this).attr("id")] = $(this).val();
});
});
function revertValues() {
for (var oldVal in oldValues) {
$("#" + oldVal).val(oldValues[oldVal]);
}
}
And then just call revertValues
when you hit OK in your confirmation dialog.
A few notes:
- I just wrote this code straight into the browser, so it's completely untested...
- Assuming you have other inputs on other tabs, you'll need to change the
:input
selector and keep different sets ofoldValues
for each tab (& then obviously only revert the values for the current tab.
精彩评论