javascript - IE 中的 $(document).ready() ,带有 require.js 优化代码

标签 javascript jquery requirejs require

我在 IE 中加载 JS 时遇到问题。我的文档就绪仅在按 ctrl+r 时运行。仅当使用 requirejs 优化器和 IE 时才会出现这种情况。如果我不运行优化器,我可以在其他浏览器和 IE 中工作。

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();
});

});

最佳答案

更改为使用 domReady!模块。

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

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

关于javascript - IE 中的 $(document).ready() ,带有 require.js 优化代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11223795/

相关文章:

JavaScript 正则表达式 : Escape the string "c++"?

javascript - 类方法可以在 ES 6 或 7 中声明为引用吗?

javascript - ink.sapo.pt 如何使用此表单验证(onSuccess 回调)

angularjs - 使用 RequireJS 延迟加载 AngularJS 模块

twitter-bootstrap - 使用 RequireJS 在 Ladda 中未定义 Spinner

javascript - 桌面 Safari/Chrome 和移动 Safari 之间的字体颜色差异

javascript - 将对象转换为 json 时,JSON.stringify 返回 []

javascript - 创建一个 Jquery 对象的对象

javascript - 在 Jquery 中使用变量作为对象名称

javascript - 需要 js Backbone JS 全局模型