0

我不能用 prev 更改 css,我的错误在哪里?小提琴链接

坦克寻找!


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>

查询:

  $("input").focus(function () {
    $(this).prev("label").css("border-bottom", "1px dotted #63aec4");
  });
4

5 回答 5

5
$(this).parent("label").css("border-bottom", "1px dotted #63aec4");
于 2011-04-19T15:02:40.843 回答
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="" />
于 2011-04-19T15:05:53.970 回答
1

请先看这里, 我的小提琴
首先你必须在添加输入之前关闭你的标签标签。

于 2011-04-19T15:07:20.850 回答
0

您不是在寻找您旁边<input>元素- 您正在寻找它的parent

$(this).parent('label')...
于 2011-04-19T15:04:08.767 回答
0
$(this).closest("label").css("border-bottom", "1px dotted #63aec4");
于 2011-04-19T15:04:53.667 回答