Are there any events available for the reset option for input search?

后端 未结 10 2030
陌清茗
陌清茗 2020-12-29 05:09

In HTML5 there is a new input type, \'search\'. On most browser it\'s just remain to a simple \'text\' input, but for webkit based browsers, it adds a little cross to reset

10条回答
  •  悲&欢浪女
    2020-12-29 05:15

    Am not sure, if still someone is looking for a solution. However below code snippet/tricks worked for me. CSS to complete hide the clear(X) icon and if you don't want to hide the clear(X) icon but need to handle then JS code snippet would help.

    CSS trick:

    #textFieldId::-ms-clear {display: none;} -- For a particular text field

    or

    input[type=text]::-ms-clear { display: none; } -- for all text fields in scope

    OR

    JavaScript trick (to reset the text field value to empty/blank and fire the html event KeyUp. Accordingly you can change per your need)

    $('#textFieldId').bind("mouseup", function() {
            var $input = $(this);
            var oldValue = $input.val();
            if (oldValue == "") {
                return;
            }
            setTimeout(function() {
                var newValue = $input.val();
                if (newValue == "") {
                    $input.trigger("keyup");
                }
            }, 1);
        });
    

提交回复
热议问题