Microsoft浏览器的自动完成获取父项失败

时间:2018-11-23 20:04:49

标签: jquery-ui-autocomplete

我们正在为公益慈善组织做一些公益活动。

对于那些在2018年感恩节假期周末可能放松的技术专家来说,这是一个很棒的想法。随附的html适用于Chrome和Firefox,但不适用于Microsoft Edge或Internet Explorer。

本质上,每当最终用户更改autocomplete的值时,我们都需要获取autocomplete的父div。

这是一个静态html文件,可以在您的PC上运行。 (1)显示调试控制台 (2)一次更改3个标签,然后 (3)记录了代码以解释问题

RSVP是您看到的解决方法吗。

<!DOCTYPE html>
<html lang="en">
<head>
        <meta http-equiv="X-UA-Compatible" content="IE=Edge" charset="utf-8">                                     
        <link href = "https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css" rel = "stylesheet">
        <link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">  
        <script src='https://code.jquery.com/jquery-1.12.4.js'> </script>          
        <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>  

   <script> 

       $(document).ready(function () {

            RegisterAutoCompleteHandlers();

            $('#MbbDwTable').find('input').on('change', function () {
                EndUserChangedDataValue(this);
            });
            $('#MbbDwTable').on('autocompletechange', function (event, ui) {
                    EndUserChangedDataValue(ui);
            });

            alert('$(document).ready() successful - Jesus Reigns \r\n'  );

       }); // end of ready() 

        function IsMicrosoftBrowser()
        {
            var isIE = /*@cc_on!@*/false || !!document.documentMode; // Internet Explorer 6-11
            var isEdge = !isIE && !!window.StyleMedia;               // Edge 20+
            if ( isEdge || isIE )
                return true;
            else    
                return false;
       }

        function RegisterAutoCompleteHandlers()
        {
                $('table tbody tr').find('td.AutoComplete input').each(function (index) { 
                            var trID  =  $(this).closest('tr').attr('id');
                            var acID = $(this).attr('id');
                            const tags = GetAvailableTags(acID);
                            $(this).autocomplete({source: tags});
                            var x = 1;
                });
        }

        function EndUserChangedDataValue(inputField) {

            //setTimeout(function () {

                    /*********************************************
                     * This gets the parent <div> for 
                     * standard <input> tags.
                     * However, for <input> tags within a jquery <autocomplete> this
                     *   -- works just fine in Chrome & Firefox
                     *   -- but returns "undefined" in I.E. and Edge
                     **********************************************/
                    var parent = $(inputField).parents('div').attr('id');

                    if (typeof parent == 'undefined') {

                        if ( IsMicrosoftBrowser() )
                        {   
                            console.log( 'need a microsoft workaround !?!?!?' );
                        }

                        // for <autocomplete> tags in ALL browsers, 
                        // EndUserChangedDataValue() is erroneously 
                        // called a 2nd time; this if() causes the 2nd call
                        // to be ignored
                        return;
                    }
                    else
                    {
                        console.log( 'EndUserChangedDataValue() success on 1st try: ' + parent)
                    }
            //}, 10);

            console.log( 'EndUserChangedDataValue() ending ' + parent)
        }


        function GetAvailableTags( name )  // for AutoCompletes 
        { 
            var availableTags;  
            switch ( name)            { 
                 case 'TransTypeId': 
                       availableTags =  [  { "id": "-1", "value": "<tbd>"}, { "id": "1", "value": "01-Charity"}, { "id": "2", "value": "01-Charity:Hosanna Church"}, { "id": "3", "value": "01-Charity:LLO"}, { "id": "4", "value": "01-Charity:MFC"}, { "id": "104", "value": "01-Charity:Needy People"}, { "id": "5", "value": "01-Charity:other"}, { "id": "6", "value": "01-Charity:Rock of SW Church"}, { "id": "7", "value": "02-Biz"}, { "id": "110", "value": "02-Biz:1099 Salaries"}, { "id": "8", "value": "02-Biz:Biz Tax"}, { "id": "113", "value": "02-Biz:Employment Expense"}, { "id": "9", "value": "02-Biz:Event Ins"}, { "id": "117", "value": "02-Biz:Federal Income Tax"}, { "id": "127", "value": "02-Biz:InternetFees-WebHosting-DomainNames"}, { "id": "10", "value": "02-Biz:ISP-WebHosting-DomainNames"}, { "id": "11", "value": "02-Biz:Jewelry & Church Envelops"}, { "id": "103", "value": "02-Biz:Office Rent"}, { "id": "129", "value": "02-Biz:Outreach Products"}, { "id": "13", "value": "02-Biz:Telecomm-phone"}, { "id": "100", "value": "02-Biz:to be Reimbursed"}, { "id": "14", "value": "03-Shelter"}, { "id": "15", "value": "03-Shelter:Cleaniing-Yard Work"}, { "id": "16", "value": "03-Shelter:Home Repair-Improvement"}, { "id": "17", "value": "03-Shelter:Moving - Relocation"}, { "id": "18", "value": "03-Shelter:Real Estate Rent"}, { "id": "112", "value": "03-Shelter:Tenant Insurance"}, { "id": "19", "value": "03-Shelter:Util"}, { "id": "20", "value": "03-Shelter:Util:ECUA"}, { "id": "21", "value": "03-Shelter:Util:Electicity"}, { "id": "22", "value": "03-Shelter:Util:Garbage Collection"}, { "id": "24", "value": "03-Shelter:Util:Mobile/Cell Phone"}, { "id": "23", "value": "03-Shelter:Util:Natural Gas & Firewood"}, { "id": "143", "value": "03-Shelter:Util:Telecomm-Phone"}, { "id": "25", "value": "03-Shelter:Util:water"}, { "id": "26", "value": "04-Transporation"}, { "id": "27", "value": "04-Transporation:Auto Insurance"}, { "id": "28", "value": "04-Transporation:Auto License Fees"}, { "id": "29", "value": "04-Transporation:Auto Repair-Dodge Truck"}, { "id": "99", "value": "04-Transporation:Auto Repair-Rogue"}, { "id": "30", "value": "04-Transporation:Auto Repair-Spectra"}, { "id": "31", "value": "04-Transporation:Petrol"}, { "id": "107", "value": "04-Transporation:Purchase-Rogue 2016"}, { "id": "32", "value": "05-Health Care"}, { "id": "33", "value": "05-Health Care:Chiropractor-Massage"}, { "id": "34", "value": "05-Health Care:Dentist"}, { "id": "35", "value": "05-Health Care:Eye Care"}, { "id": "156", "value": "05-Health Care:Health Ins"}, { "id": "36", "value": "05-Health Care:Health Ins Premium"}, { "id": "37", "value": "05-Health Care:Medicine"}, { "id": "38", "value": "05-Health Care:Primary Medical Care"}, { "id": "39", "value": "06-Ministry"}, { "id": "40", "value": "06-Ministry:Advertising"}, { "id": "106", "value": "06-Ministry:banquets/luncheons"}, { "id": "41", "value": "06-Ministry:Bldg Rental"}, { "id": "162", "value": "06-Ministry:Book Table"}, { "id": "42", "value": "06-Ministry:Book Table Expense"}, { "id": "43", "value": "06-Ministry:Humanitarian Outreach"}, { "id": "44", "value": "06-Ministry:Music"}, { "id": "45", "value": "06-Ministry:Preaching"}, { "id": "46", "value": "06-Ministry:Shipping"}, { "id": "47", "value": "06-Ministry:stipend 1099"}, { "id": "48", "value": "06-Ministry:Training"}, { "id": "49", "value": "06-Ministry:warehouse-storage"}, { "id": "50", "value": "07-Gifts"}, { "id": "51", "value": "07-Gifts:to Others"}, { "id": "52", "value": "09-GeneralExpenses"}, { "id": "53", "value": "09-GeneralExpenses:Beauty Services & Supplies"}, { "id": "54", "value": "09-GeneralExpenses:Clothing"}, { "id": "55", "value": "09-GeneralExpenses:Decorations"}, { "id": "115", "value": "09-GeneralExpenses:Dry Cleaning"}, { "id": "56", "value": "09-GeneralExpenses:Education-Career"}, { "id": "57", "value": "09-GeneralExpenses:Electronic Equipment"}, { "id": "58", "value": "09-GeneralExpenses:Entertainment-Movies-etc"}, { "id": "179", "value": "09-GeneralExpenses:Food-Groceries-MiscSupplies"}, { "id": "60", "value": "09-GeneralExpenses:Furniture-Bedding"}, { "id": "59", "value": "09-GeneralExpenses:Groceries / Misc Supplies"}, { "id": "61", "value": "09-GeneralExpenses:Gym Membership"}, { "id": "62", "value": "09-GeneralExpenses:Home Appliances-large"}, { "id": "63", "value": "09-GeneralExpenses:Home Appliances-small"}, { "id": "64", "value": "09-GeneralExpenses:Jewelry-Flowers"}, { "id": "65", "value": "09-GeneralExpenses:Legal Fees"}, { "id": "66", "value": "09-GeneralExpenses:Office Supplies"}, { "id": "67", "value": "09-GeneralExpenses:Outdoor-Sports-Exercise Equip"}, { "id": "68", "value": "09-GeneralExpenses:pets"}, { "id": "69", "value": "09-GeneralExpenses:Postage-Fax"}, { "id": "70", "value": "09-GeneralExpenses:Printing"}, { "id": "71", "value": "09-GeneralExpenses:Restaurants-Dining"}, { "id": "72", "value": "09-GeneralExpenses:Restaurants-FastFood"}, { "id": "73", "value": "09-GeneralExpenses:Software"}, { "id": "114", "value": "09-GeneralExpenses:storage-packing supplies"}, { "id": "74", "value": "09-GeneralExpenses:Tools"}, { "id": "75", "value": "10-Financial"}, { "id": "76", "value": "10-Financial:Bank Fees"}, { "id": "77", "value": "10-Financial:Interest Expense"}, { "id": "78", "value": "11-Travel"}, { "id": "79", "value": "11-Travel:Air-Train-Ferry"}, { "id": "80", "value": "11-Travel:Car Rental & Taxi"}, { "id": "81", "value": "11-Travel:Lodging"}, { "id": "111", "value": "11-Travel:Luggage/supplies"}, { "id": "82", "value": "11-Travel:Parking-BaggageCarts-Cargo"}, { "id": "83", "value": "12-Insurance"}, { "id": "84", "value": "12-Insurance:Life Insurance"}, { "id": "85", "value": "13-Relocation"}, { "id": "86", "value": "Income"}, { "id": "87", "value": "Income:Adhoc"}, { "id": "88", "value": "Income:Conrad-Mis2000 Salary"}, { "id": "89", "value": "Income:Donations"}, { "id": "101", "value": "Income:Eagle Creek"}, { "id": "90", "value": "Income:Interest and Dividends"}, { "id": "116", "value": "Income:KSS-Allied-TX"}, { "id": "91", "value": "Income:LifeLine Hosting"}, { "id": "92", "value": "Income:Ministry Sales"}, { "id": "93", "value": "Income:State Of NV"}, { "id": "108", "value": "Income:Unemployment Ins"}, { "id": "95", "value": "Not Sure"}, { "id": "96", "value": "Taxes"}, { "id": "97", "value": "Taxes:Biz Tax"}, { "id": "102", "value": "To Be Reimbursed"}, { "id": "98", "value": "Xfer of Funds"}]; 
                     break; 
                 case 'ProjectID': 
                       availableTags =  [  { "id": "91", "value": "2018-02 detox voodoo/witch-doctor diet"}, { "id": "94", "value": "2018-07 Move to Infinity-Triangle"}, { "id": "95", "value": "2018-08 FCD Training Maria"}, { "id": "30", "value": "2nd wedding anniversary"}, { "id": "135", "value": "bed frame   Feb 2016"}, { "id": "35", "value": "bed frame Feb 2016"}, { "id": "67", "value": "Cough- Conrad 2017"}, { "id": "141", "value": "Evaporative Cooler May 2016"}, { "id": "41", "value": "Evaporative Cooler May 2016"}, { "id": "50", "value": "Girwood/Seatle Nov2016"}, { "id": "46", "value": "Honeymoon 2016 sep 2016"}, { "id": "72", "value": "Honeymoon 2017 sep"}, { "id": "155", "value": "Honeymoon 2018 -- Seguin TX"}, { "id": "6", "value": "Honeymoon-Feb2014"}, { "id": "25", "value": "Jewelry Biz"}, { "id": "45", "value": "Kidney Stone - Conad   Aug 2016"}, { "id": "13", "value": "Kirkwood CA mini-vacation - Jul2014"}, { "id": "1", "value": "LLO 2014-01 -Turlock Jan2014"}, { "id": "10", "value": "LLO 2014-01 Stockton"}, { "id": "7", "value": "LLO 2014-02 -Dallas-Feb2014"}, { "id": "4", "value": "LLO 2014-03 AK-March2014"}, { "id": "18", "value": "LLO 2014-10 -Angoon Oct2014"}, { "id": "17", "value": "LLO 2014-10 -Turlock Oct2014"}, { "id": "16", "value": "LLO 2014-10 Stockton"}, { "id": "19", "value": "LLO 2015-01 -Anchorage/Moravian Jan2015"}, { "id": "21", "value": "LLO 2015-02 Turlock"}, { "id": "20", "value": "LLO 2015-04 -Nome Apr2015"}, { "id": "23", "value": "LLO 2015-04 -PNS Apostolic Women"}, { "id": "24", "value": "LLO 2015-05 Stockton CA"}, { "id": "22", "value": "LLO 2015-06 RenoBlessing"}, { "id": "26", "value": "LLO 2015-10 Alaska"}, { "id": "29", "value": "LLO 2015-11 -Turlock Nov2015"}, { "id": "28", "value": "LLO 2015-12 MFC"}, { "id": "34", "value": "LLO 2016-01 -Turlock Jan2016"}, { "id": "33", "value": "LLO 2016-02 Alaska"}, { "id": "36", "value": "LLO 2016-03 -Anchorage Mar2016"}, { "id": "31", "value": "LLO 2016-04 -Apostolic Women Apr 2016"}, { "id": "37", "value": "LLO 2016-04 -CRIT Indian Nation Apr2016"}, { "id": "39", "value": "LLO 2016-06 -ANC/Barrow"}, { "id": "43", "value": "LLO 2016-06 -Voice in Wilderness Jun-2016"}, { "id": "40", "value": "LLO 2016-10 -AK-Oct 2016   ANC & Fairbanks"}, { "id": "49", "value": "LLO 2016-11  AK-Nov 2016   ANC"}, { "id": "42", "value": "LLO 2016-11 -Savoonga-Ncv 2016"}, { "id": "48", "value": "LLO 2016-11 MFC"}, { "id": "47", "value": "LLO 2016-11 Turlock Sep2016"}, { "id": "53", "value": "LLO 2016-12 MFC"}, { "id": "54", "value": "LLO 2017-01 ANC/Kotz/et al."}, { "id": "56", "value": "LLO 2017-03 FCD Training"}, { "id": "51", "value": "LLO 2017-03 Women Conf Mar2017 ANC"}, { "id": "58", "value": "LLO 2017-04 MFC Womens Conference"}, { "id": "57", "value": "LLO 2017-04 Parker AZ"}, { "id": "61", "value": "LLO 2017-05 turlock"}, { "id": "63", "value": "LLO 2017-06 MFC FCD"}, { "id": "69", "value": "LLO 2017-09 scouting trip and Barrow"}, { "id": "73", "value": "LLO 2017-09 Turlock Sep2017"}, { "id": "68", "value": "LLO 2017-10 Moravian-ANC, Kodiak Frbnks, Venetie"}, { "id": "75", "value": "LLO 2017-11 Beauty for Ashes Training"}, { "id": "60", "value": "LLO 2017-11 Kivalina Blessing"}, { "id": "70", "value": "LLO 2017-11 MFC Anchorage"}, { "id": "81", "value": "LLO 2017-11 Perkins Family"}, { "id": "79", "value": "LLO 2017-12 MFC Foresight Training"}, { "id": "76", "value": "LLO 2017-12 MFC Training"}, { "id": "77", "value": "LLO 2018-01 ANC/Kotzebue"}, { "id": "80", "value": "LLO 2018-01 Gambell"}, { "id": "82", "value": "LLO 2018-01 Turlock CA"}, { "id": "78", "value": "LLO 2018-02 Fairbanks"}, { "id": "84", "value": "LLO 2018-02 Micron"}, { "id": "83", "value": "LLO 2018-02 Turlock CA"}, { "id": "86", "value": "LLO 2018-03 Anchorage"}, { "id": "85", "value": "LLO 2018-03 FCD Training Conrad"}, { "id": "88", "value": "LLO 2018-04 CRIT Reservation"}, { "id": "90", "value": "LLO 2018-04 MFC Wonder Working Women"}, { "id": "92", "value": "LLO 2018-08 Blythe/WhiteRiver"}, { "id": "96", "value": "LLO 2018-09 Turlock CA"}, { "id": "98", "value": "LLO 2018-10 Anchorage/Cordova"}, { "id": "97", "value": "LLO 2018-10 Fairbanks"}, { "id": "100", "value": "LLO 2018-11 Barrow/Anchorage"}, { "id": "156", "value": "LLO 2018-11 Winterhaven CA"}, { "id": "99", "value": "LLO 2018-11 Yuma CA"}, { "id": "2", "value": "LLO Book Table"}, { "id": "110", "value": "LLO Stockton- Jun2014"}, { "id": "116", "value": "LLO Stockton- Oct2014"}, { "id": "133", "value": "LLO- AK Feb2016"}, { "id": "126", "value": "LLO- AK Oct2015"}, { "id": "3", "value": "LLO- Amazon/Ministry Sales"}, { "id": "153", "value": "LLO- MFC Dec 2016"}, { "id": "148", "value": "LLO- MFC Nov 2016"}, { "id": "128", "value": "LLO- PNS/MFC Dec2015"}, { "id": "122", "value": "LLO- RenoBlessing Jun2015"}, { "id": "124", "value": "LLO- Stockton CA May2015"}, { "id": "121", "value": "LLO- Turlock Feb2015"}, { "id": "147", "value": "LLO- Turlock Sep2016"}, { "id": "151", "value": "LLO- Women Conf Mar2017 ANC"}, { "id": "38", "value": "LLO- Your Unseen Enemy Revealed"}, { "id": "139", "value": "LLO-AK-June2016"}, { "id": "104", "value": "LLO-AK-March2014"}, { "id": "149", "value": "LLO-AK-Nov 2016   ANC"}, { "id": "140", "value": "LLO-AK-Oct 2016   ANC & Fairbanks"}, { "id": "136", "value": "LLO-Anchorage Mar2016"}, { "id": "119", "value": "LLO-Anchorage/Moravian Jan2015"}, { "id": "118", "value": "LLO-Angoon Oct2014"}, { "id": "131", "value": "LLO-Apostolic Women Apr 2016"}, { "id": "137", "value": "LLO-CRIT Indian Nation Apr2016"}, { "id": "107", "value": "LLO-Dallas-Feb2014"}, { "id": "120", "value": "LLO-Nome Apr2015"}, { "id": "123", "value": "LLO-PNS Apostolic Women"}, { "id": "142", "value": "LLO-Savoonga-Ncv 2016"}, { "id": "101", "value": "LLO-Turlock Jan2014"}, { "id": "134", "value": "LLO-Turlock Jan2016"}, { "id": "129", "value": "LLO-Turlock Nov2015"}, { "id": "117", "value": "LLO-Turlock Oct2014"}, { "id": "143", "value": "LLO-Voice in Wilderness Jun-2016"}, { "id": "15", "value": "Mammoth Lakes CA mini-vacation - Sep2014"}, { "id": "87", "value": "Maria Detox Feb-2018"}, { "id": "44", "value": "Maria Trip- Bothel WA   Aug 2016"}, { "id": "66", "value": "Maria twins"}, { "id": "8", "value": "MbbDw-Feb2014"}, { "id": "5", "value": "MbbDw-Jan2014"}, { "id": "14", "value": "medical stupidity - Sep 2014"}, { "id": "89", "value": "Move to Texas 2018-04"}, { "id": "65", "value": "New tooth - Conrad - 2017"}, { "id": "9", "value": "Panama Beach - May2014"}, { "id": "59", "value": "Park City Utah- Vacation 2017"}, { "id": "52", "value": "RedWing vs Sharks Jan2017"}, { "id": "27", "value": "Relocation to Galena Sep2015"}, { "id": "11", "value": "Relocation to NV- Jun2014"}, { "id": "74", "value": "Rogue crash"}, { "id": "71", "value": "Seattle 2017-Sep"}, { "id": "55", "value": "Snow Storms-Jan2017"}, { "id": "64", "value": "Solar Eclipse 2017-08"}, { "id": "12", "value": "Tahoe Donner- 4Jul2014"}, { "id": "32", "value": "tbd"}, { "id": "62", "value": "Todd/Madison trip 2017-07"}]; 
                     break; 
              } 
            return availableTags; 

        } // end of GetAvailableTags()    

    </script> 

    <style>         
                table { border: 3px solid red;  }
                th, td {border: 1px solid black; }
    </style>

</head>

    <body>

        <h1> LifeLine Outreach Public Charity</div></h1> <br />

        <table id='MbbDwTable'> 
            <tbody> 
                <tr id='12669'> 
                    <td class='userInput' name='TransactionID'  > 
                        <div id='TransactionIDDiv'>  
                            <input type='text' value='10303'> 
                       </div> </td> 
                    <td class='userInput AutoComplete' name='TransTypeId'  style='display: block'  >
                               <div id='TransTypeIdDiv'>
                                  <label for='TransTypeId' >  </label> 
                                  <input id='TransTypeId' value='09-GeneralExpenses:Software'>
                               </div> 
                    </td> 
                    <td class='userInput AutoComplete' name='ProjectID'  style='display: block'  >
                               <div id='ProjectIDDiv' class='ui-front'>
                               <!-- By default the autocomplete dropdown is appended to the web page <body>
                                    The ui-front class causes the autocomplete dropdown to be appended to this div
                                    Using ui-front has no material effect in Chrome or Firefox
                                    but might be useful for the microsoft browser work-around
                                -->
                                  <label for='ProjectID' >  </label> 
                                  <input id='ProjectID' value='tbd' >
                               </div> 
                    </td> 
                </tr> 
            </tbody> 
        </table> 

    </body> 

</html> 

0 个答案:

没有答案