我在 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/