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..." />

私は基本的に、ページがロードされたときに2つの入力フィールドの背景にクラス「ハイライト」を追加したいと考えています...タイトルと値の両方が同じ場合のみ。

ありがとう - アート

4

1 に答える 1

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