簡體   English   中英

如何使用點擊事件jQuery處理模糊事件

[英]How to handle blur event with click event jquery

我有這樣的html標記

<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>

二手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");
    });

  });

在我的情況下,我的輸入框的寬度為140px,當用戶專注於輸入框時,我會將其設置為284px的動畫,而當我單擊任何地方時,我將處理模糊事件。 現在我的要求是,當我單擊十字圖標時,輸入框內有一個十字圖標,我必須執行一些任務,但我不想在單擊十字圖標時產生模糊。 如果已有模糊事件,請建議我如何處理點擊。

如果您可以檢測到該圖標,請點擊設置一些全局javascript標志,例如

iconclicked = true;

使用此iconclick中的模糊方法,如果為true,則返回

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM