简体   繁体   English

:与按钮输入和搜索同时聚焦

[英]:focus simultaneously with input of button and search

I am attempting to give an input of text and an button pseudo :focus. 我试图给文本输入和按钮伪:focus。 I can do that, no problem. 我可以做到,没问题。 What is my problem is though is I want when I click on the input of text, that it not only changes the elements on the input text but also the button. 我的问题是,当我单击文本输入时,我希望它不仅更改输入文本上的元素,而且还更改按钮。 Is this possible in JS? 在JS中可以吗? Would you just create a function saying when that is clicked change the elements of that? 您是否会创建一个函数,说明单击该函数时会更改其元素? Or even in jQuery? 甚至在jQuery中?

Here it goes: 它去了:

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

https://jsfiddle.net/fxzuu3yz/ https://jsfiddle.net/fxzuu3yz/

I'm pretty sure you're looking for a jQuery way of doing this: 我很确定您正在寻找这样做的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> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM