我正在使用这个命令: $( "#result").load( "ajax/test.html");
将 html 页面的内容加载到 div 中。
我的问题是我输入之后如何知道我输入了什么?返回已位于 div 内的 html 页面的函数。
最佳答案
您可以将当前加载的页面 (currentPage
) 存储在变量中,并将加载的页面与此变量的值进行比较:
<div id="result"></div>
<input type="button" onclick="load('test1.html')" value="Load">
<script>
var currentPage;
function load(page) {
if ( currentPage != page ) {
$("#result").load(page, function () {
currentPage = page;
});
}
else console.log('already loaded');
}
</script>
关于javascript - div中加载了什么页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27076333/