简体   繁体   English

指定输入目标模糊功能

[英]Specifiy input targeted blur function

My function works as it should. 我的功能可以正常工作。 is there a way to remove the function from a specific input? 有没有办法从特定的输入中删除功能? Because it changes all inputs.. i have 2 check boxes and 1 input that i need to not have this function on. 因为它会更改所有输入。.我有2个复选框和1个输入,我不需要启用此功能。

$('input').blur(function(){
    $('input').parent().removeClass("gray");
})
    .focus(function() {     
        $(this).parent().addClass("gray")
});

Try adding a class to the input and checkbox that you don't want the onblur functions, then update the code as below 尝试在不需要onblur函数的输入和复选框中添加一个类,然后按如下所示更新代码

Add the class to the three inputs that you don't want this feature class添加到不需要此功能的三个输入中

$('input').not( ".class" ).blur(function() {
    $(this).parent().removeClass("gray");
  })
  .focus(function() {
    $(this).parent().addClass("gray")
  });

Hope this helps what you need. 希望这对您有帮助。

Use this context, $('input') will select all the <input> elements, this in the callback will hold the element on which event is invoked! 使用this上下文, $('input')将选择所有<input>元素, thiscallback中将保留在其上调用event的元素!

 $('input').blur(function() { $(this).parent().removeClass("gray"); }) .focus(function() { $(this).parent().addClass("gray") }); 
 .gray { background: gray; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <div> <input type="text"> </div> <div> <input type="text"> </div> 

If you have id's for those three inputs you can use this code snippet. 如果您具有这三个输入的ID,则可以使用此代码段。

$('input').blur(function(){
    $(this).parent().removeClass("gray");
 })
.focus(function() {     
    $(this).parent().not( "#id1, #id2, #id3" ).addClass("gray")
 });

It will add class to those inputs which do not match the selector. 它将为与选择器不匹配的输入添加类。

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

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