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

后端 未结 10 2027
陌清茗
陌清茗 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:26

    I don't know that this is the correct answer, but the click event handler is called when the user clears the input using the X button.

    $('input[type="search"]').click(function(event) {
        // This code runs anytime a user clicks on the input,
        // including when they clear it using the X button.
    })
    
    0 讨论(0)
  • 2020-12-29 05:32

    No, it's not possible. This UI interaction is some goodness that webkit implements, but is not actually specced. See here. So even if it were possible--you can't expect this UI to be implemented in Gecko, for example, if and when they ever add type=search.

    0 讨论(0)
  • 2020-12-29 05:35

    In my testing with MS Edge, it didn't fire any of these events. I tried input, change, click, and search and they weren't triggered when you click the X. I even tried directly setting input.onchange, input.onclick, etc - still nothing.

    The only events that seemed to fire were mousedown and mouseup, but the input's value hadn't been cleared yet so I had to use a setTimeout after detecting the event.

    0 讨论(0)
  • 2020-12-29 05:37

    I suppose u want to capture event when cross button is clicked Here is one solution I found I seems to be working fine(Without setTimeout())

    $('id').bind('input propertychange', function() {
    if (this.value == ""){
        doStuff()
        $input.trigger("cleared");
    }});
    

    Hope this helps!

    0 讨论(0)
提交回复
热议问题