Select2 plug-ins ie under autofocus bug resolution method

Source: Internet
Author: User

Describe:

Select2 plug-in in IE, when the page is loaded and will automatically focus, pop-up should be clicked input will have a prompt.

Reason:

In the Select2 source code in the 1849th row or so, there is a listen to the input event codes, as follows:

this.$selection.on(‘keyup.search input‘‘.select2-search--inline‘,function (evt) {      self.handleSearch(evt);});

You can see that this is using the HTML5 input event to listen for changes in the value of input, without using events such as the traditional change or KeyDown.

The reason for this is that the input event has a bug in IE. In IE, if an input has the placeholder attribute, IE will automatically trigger the input event for this, which will not occur in other browsers.

Solution Solutions

Write a compatibility method for IE, replace the input event with the KeyDown event when judging as ie.

varIsie = ( function () {    varUA = Window.navigator.userAgent.toLowerCase ();if(Ua.indexof ("MSIE") >0|| Ua.indexof ("Trident") >0) {return true; }Else{return false; }}());varInput_event =!isie?' input ':' KeyDown '; this.$selection. On (' Keyup.search '+input_event,'. Select2-search--inline ', function (evt) {       Self. Handlesearch (evt);});

Article FOREVERCJL
Article original CSDN Link: www.foreverpx.cn
Reprint please indicate the source.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Select2 plug-ins ie under autofocus bug resolution method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.