0

我要做的就是检查文本字段是否已更改。如果没有,我想在按下提交时突出显示这些框。我怎么做?看起来很简单,但不确定为什么其他所有解决方案都如此复杂。

4

3 回答 3

4

基于 Pim 的回答,您可以changed使用 jQuery 的数据 API 为每个文本字段关联标志。

// initially, assign changed to false for all text fields
$("input:text").data("changed", false);

// if any field changes, set its changed flag to true
$("input:text").change(function() {
    $(this).data("changed", true);
}

// finally on submission, get all text fields that did not
//  change by checking their "changed" property
var unchangedItems = $("input:text").filter(function() {
    return $(this).data("changed") === false;
});
于 2010-03-16T00:27:04.060 回答
2

您可以使用jQuery Validate插件。

于 2010-03-16T00:16:30.447 回答
1

基本上,你只是说它从未改变过,当它发生变化时,你设置一个标志说它已经改变:

var changed = false;
$('#textfield').change(function(){
    changed = true;
});
if(changed){
    $('.textbox').each(function(){
        $(this).addClass('.highlighted');
        //or something like this, whatever you want to do to highlight them
    });
}
于 2010-03-16T00:18:13.790 回答