简体   繁体   中英

$(document).ready() in IE with require.js optimized code

I am having a problem with loading JS in IE. My document ready only runs if press ctrl+r. This is only the case when using the requirejs optimizer and IE. I works in other browsers and in IE if I dont run the optimizer.

require(["jquery", "modals", "registermodule", "bootstrap", "personsmodule"], function($) {

//This is for placeholders in browsers that don't support it.
function createPlaceHoldersForIE(){
    if (typeof document.createElement("input").placeholder == 'undefined') {
        $('[placeholder]').focus(function() {
            var input = $(this);
            if (input.val() == input.attr('placeholder')) {
                input.val('');
                input.removeClass('placeholder');
            }
        }).blur(
                function() {
                    var input = $(this);
                    if (input.val() === '' || input.val() === input.attr('placeholder')) {
                        input.addClass('placeholder');
                        input.val(input.attr('placeholder'));
                    }
                }).blur().parents('form').submit(function() {
            $(this).find('[placeholder]').each(function() {
                var input = $(this);
                if (input.val() == input.attr('placeholder')) {
                    input.val('');
                }
            });
        });
    }
}


// This will allow $(selector).val().trim(); syntax
String.prototype.trim = function() {
    return $.trim(this);
};

$(document).ready(function() {
    createPlaceHoldersForIE();
});

});

Change to using the domReady! module.

http://requirejs.org/docs/api.html#pageload

require([
         "jquery", "modals", "registermodule", 
         "bootstrap", "personsmodule", "domReady!"
        ], 
         function($){

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM