如何获取page1中的图片数量在page2中显示?
第1页:
<!doctype html>
<html>
<head>
<title>images count</title>
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.2.1.min.js"></script> <script>
$(document).ready(function(){
$("#count").html($(".galery img").length);
});
</script>
</head>
<body>
<div id="box">
<p style="padding: 20px;">Images Count:<span id="count"></span></p>
</div>
<div class="galery">
<img src="download.png">
<img src="download.png">
<img src="download.png">
<img src="download.png">
</div>
</body>
</html>
第2页:
<!doctype html>
<html>
<head>
<title></title>
</head>
<body>
Page1 Images count:<span id="newcount"></span>
</body>
</html>
最佳答案
您可以使用 localStorage 来实现此目的:
第 1 页:
<!doctype html>
<html>
<head>
<title>images count</title>
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.2.1.min.js></script>
<script>
$(document).ready(function(){
localStorage.setItem("count", $(".galery img").length);
});
</script>
</head>
<body>
<div id="box">
<p style="padding: 20px;">Images Count:<span id="count"></span></p>
</div>
<div class="galery">
<img src="download.png">
<img src="download.png">
<img src="download.png">
<img src="download.png">
</div>
</body>
</html>
第 2 页:
<!doctype html>
<html>
<head>
<title></title>
<script>
$(document).ready(function(){
var count = localStorage.getItem("count");
$("#count").html(count)
});
</script>
</head>
<body>
Page1 Images count:<span id="newcount"></span>
</body>
</html>
基本上,在第 1 页中,您可以在本地存储中存储一些数据,在第 2 页中,您可以从本地存储中检索数据并显示它。
关于javascript - 想要显示同一文件夹中其他html页面中一个html页面的图像数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48147314/