【发布时间】:2012-02-16 17:12:53
【问题描述】:
我的表单包含许多输入字段、文本区域、单选按钮、复选框。一旦在任何字段中更改值,我应该使用字段名称、old 和新值将 ajax 发送到我的服务器。我该怎么做?
更新。这是当前的方法:
oldValueHolder = null;
$('input[type="text"]').focus(function() {
oldValueHolder = this.value;
});
$('input[type="text"]').focusout(function() {
if (this.value != oldValueHolder) alert(this.name + ': ' + oldValueHolder + ' -> ' + this.value);
});
$('input[type="checkbox"]').click(function(event) {
alert(this.name + ': ' + !$(event.target).is(":checked") + ' -> ' + $(event.target).is(":checked"));
});
但我仍然不清楚如何对单选按钮执行相同的操作。
Upd2.这是单选按钮的解决方案:
$('input[type="radio"]').change(function() {
alert(this.name + ': ' + $(this).parents("div.control-group").attr('data-original-value') + ' -> ' + this.value);
$(this).parents("div.control-group").attr('data-original-value', this.value);
});
【问题讨论】:
标签: javascript jquery ajax forms