【发布时间】:2014-04-02 16:55:50
【问题描述】:
下面的代码显示当 input 聚焦时,它的父 fieldset 背景颜色发生变化。我希望字段集保持该背景颜色,直到另一个字段集中的输入被聚焦。下面的概念有效,除非字段集包含多个输入,否则会在下一个输入聚焦时重新触发更改。有什么想法吗?谢谢!
jQuery
jQuery("input[title]").focus(function() {
jQuery(this).closest('fieldset').animate({backgroundColor: "#7e7451", color: "#ffffff"}, 'slow');
});
jQuery("input[title]").blur(function() {
jQuery(this).closest('fieldset').animate({backgroundColor: "transparent", color: "#777777"}, 'slow');
});
HTML
<fieldset name="Fieldset 1" id="fieldset1">
<legend>Fieldset 1</legend>
<label for="input1"><strong>Input 1</strong>
<input type="text" name="input1" id="input1" />
</label>
<label for="input2"><strong>Input 2</strong>
<input type="text" name="input2" id="input2" />
</label>
</fieldset>
<fieldset name="Fieldset 2" id="fieldset2">
<legend>Fieldset 2</legend>
<label for="input3"><strong>Input 3</strong>
<input type="text" name="input3" id="input3" />
</label>
<label for="input4"><strong>Input 4</strong>
<input type="text" name="input4" id="input4" />
</label>
</fieldset>
etc
【问题讨论】:
标签: javascript jquery input focus fieldset