:同时关注按钮和搜索的输入

时间:2017-04-05 00:42:47

标签: javascript jquery css

我试图输入文本和按钮伪:焦点。我能做到,没问题。我的问题是,当我点击文本输入时,我想要的是,它不仅会更改输入文本中的元素,还会更改按钮。这可能在JS吗?您是否只需创建一个函数,说明何时单击该元素会更改其中的元素?甚至在jQuery中?

2 个答案:

答案 0 :(得分:1)

这就是:

#inputText:focus{
  border: 1px dashed black;
}
#inputText:focus ~ #button {
  background: red;
}

https://jsfiddle.net/fxzuu3yz/

答案 1 :(得分:0)

我很确定您正在寻找一种jQuery方式:



function update() {
  $(this).parent().toggleClass("active");
}

$(".main input").on("focus", update);
$(".main input").on("blur", update);

.active input {
  border: 1px dashed black;
}

.active button {
  background:red;
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="main">
  <input type="text" />
  <button>Go!</button>
</div>
&#13;
&#13;
&#13;