我无法用prev更改css,我的错误在哪里? Fiddlelink
寻找坦克!
的CSS:
.i1 {
float: right;
height: 18px;
margin-top: 6px;
}
label {
border-bottom: 1px dotted #CCCCCC;
clear: both;
float: left;
height: 25px;
margin: 5px 0 0;
width: 450px;
line-height: 32px;
}
Html:
<label>Titel:<input class="i1" type="text" name="titel" value="" /></label>
<label>Vorname:<input class="i1" type="text" name="vorname" value="" /></label>
<label>Nachname:<input class="i1" type="text" name="nachname" value="" /></label>
Jquery的:
$("input").focus(function () {
$(this).prev("label").css("border-bottom", "1px dotted #63aec4");
});
答案 0 :(得分:5)
$(this).parent("label").css("border-bottom", "1px dotted #63aec4");
答案 1 :(得分:3)
那是因为你把所有东西都放到了标签标签上......尝试改变这样的html:
<label for="titel">Titel:</label><input tabindex="1" class="i1" type="text" name="titel" value="" />
<label for="vorname">Vorname:</label><input class="i1" type="text" name="vorname" value="" />
<label for="nachname">Nachname:</label><input class="i1" type="text" name="nachname" value="" />
答案 2 :(得分:1)
答案 3 :(得分:0)
您不是在寻找 <{1>}旁边的元素 - 您正在寻找它的父。
<input>
答案 4 :(得分:0)
$(this).closest("label").css("border-bottom", "1px dotted #63aec4");