简体   繁体   中英

How to handle blur event with click event jquery

I have a html markup like this

<li id="fSearch" class="alwsShown">
            <div class="dark overflowHidden" id="fSearchBg">
                            <input type="text" id="filter" name="" style="width:140px" tabindex="1" class="fullWidth opt resetBorderNShd resetShd" value="" autocomplete="off" title="Search" value=""/>
             <span id="stopSearch" class="imgSprite stopSearch displayNone poAbs"></span>
            </div>

          </li>

Used jquery

var test = function() {
    var self = this,
    $filter = $("#filter"),
    $fSearchBg = $("#fSearchBg"),
    $stopSearch = $(".stopSearch");
    // Blur
    $filter.blur(function() {
      $filteranimate({
        width: "140px"
      }, 200, function() {
        $fSearchBg.removeClass("light").addClass("dark");
        $stopSearch.hide();
      });
    });
    $stopSearch.click(function(event){
      $filter.val("");
      $(this).hide('fast');
      event.preventDefault()
      event.stopPropagation();

    });
    // Focus
    $filter.focus(function() {
      // animate
      $filter.animate({
        width: "285px"
      }, 200);
      $fSearchBg.removeClass("dark").addClass("light");
    });

  });

In my case my input box is having 140px of width, when a user focus on input box I am animating it to 284px and when i click anywhere I am handling a blur event. Now my requirement is there is a cross icon inside input box when i click on cross icon, I have to perform some task but I didn't want to fire blur when i click on cross icon. please suggest me how to handle click if already there is a blur event.

If you can detect the icon click set some global javascript flag like

iconclicked = true;

Use this iconclicked in blur method and return if it is true

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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