1

jQuery:

$(document).ready(function() {
    $('.text').load(function() {
        if (this.value == this.title) {
            $('.text').addClass("highlight");
        }
    });
});

CSS:

.highlight
{
  background: #FFA9B8;
  border: 1px solid red;
}

HTML

<label for="first_name">first name: </label>
<input type = "text" name = "first_name" class = "text" value = "First..." title = "First..." />
<label for="last_name">last name: </label>
<input type = "text" name = "last_name" class = "text" value = "Last..." title = "Last..." />

我本质上想在加载页面时将类“highlight”添加到 2 个输入字段的背景中……仅当标题和值都相同时。

谢谢-艺术

4

1 回答 1

2
$(document).ready(function(){
   $('.text').filter(function(){
        return this.value === this.title
   }).addClass('highlight')
});
于 2012-12-17T20:53:02.190 回答