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个输入字段的背景中......只有当标题和值都相同时才会这样。
谢谢 -art
答案 0 :(得分:2)
$(document).ready(function(){
$('.text').filter(function(){
return this.value === this.title
}).addClass('highlight')
});