当清除IE10上的文本输入时清除图标,触发事件 [英] Event fired when clearing text input on IE10 with clear icon

查看:103
本文介绍了当清除IE10上的文本输入时清除图标,触发事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在chrome上,当用户点击清除按钮时,搜索事件将触发搜索输入。

On chrome, the "search" event is fired on search inputs when user clicks the clear button.

有没有办法在javascript中捕获相同的事件Internet Explorer 10?

Is there a way to capture the same event in javascript on Internet Explorer 10?

推荐答案

我终于找到了唯一的解决方案:

The only solution I finally found:

// There are 2 events fired on input element when clicking on the clear button:
// mousedown and mouseup.
$("input").bind("mouseup", function(e){
  var $input = $(this),
      oldValue = $input.val();

  if (oldValue == "") return;

  // When this event is fired after clicking on the clear button
  // the value is not cleared yet. We have to wait for it.
  setTimeout(function(){
    var newValue = $input.val();

    if (newValue == ""){
      // Gotcha
      $input.trigger("cleared");
    }
  }, 1);
});

这篇关于当清除IE10上的文本输入时清除图标,触发事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆