当使用
所以我尝试使用jquery的
index.html:
$(document).ready(function(){...});
(版本1)时,文档准备函数会无限触发。我猜测是每次jquery的.load函数完成时都会触发ready? 希望确认一下。所以我尝试使用jquery的
$(document).one('ready', function(){...});
函数(版本2),但是函数根本不触发。这里有什么问题吗?index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<script src="/vendor/jquery/jquery-3.1.0.min.js"></script>
<script src="/js/index.js"></script>
</head>
<body>
<div class="index__header"></div>
<div class="index__content"></div>
</body>
</html>
index.js 版本 1:
var _index = {
loadLogin : function () {
$(".index__content").load("/view/login.html");
}
};
$(document).ready ( function () {
$(".index__header").load("/view/header.html");
_index.loadLogin();
});
index.js 版本 2:
var _index = {
loadLogin : function () {
$(".index__content").load("/view/login.html");
}
};
$(document).one ('ready', function () {
console.log('ready...');
$(".index__header").load("/view/header.html");
_index.loadLogin();
});
$(function() { $(".index__content").load("/view/header.html",function() { $(".index__content").load("/view/login.html"); });});
- mplungjan