Jquery 如何将随机html页面从文件夹加载到div中
我正在寻找将随机html页面(从包含所有页面的文件夹)加载到div中的正确方法。 这就是我现在所做的:Jquery 如何将随机html页面从文件夹加载到div中,jquery,html,Jquery,Html,我正在寻找将随机html页面(从包含所有页面的文件夹)加载到div中的正确方法。 这就是我现在所做的: <html> <head> <script src="http://code.jquery.com/jquery-1.9.1.js"></script> <script> $(function() { $("#CONTENTS").load("contenuti/1.html"); }); </script>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script>
$(function() {
$("#CONTENTS").load("contenuti/1.html");
});
</script>
</head>
<body>
<div id="CONTENTS"></div>
</body>
</html>
$(函数(){
$(“#CONTENTS”).load(“contentnuti/1.html”);
});
我认为正确的方法是转换“*.html”中的“1.html”,然后插入一个随机代码。
有人能帮我吗?你可以这样做:
$(function() {
var max = 10, min = 1;
$("#CONTENTS").load("contenuti/"+Math.floor(Math.random()*(max-min+1)+min)+".html");
});
以上内容将随机选取从1到10的html页面
随机数代码礼貌:方济各回答问题您可以这样做:
$(function() {
var max = 10, min = 1;
$("#CONTENTS").load("contenuti/"+Math.floor(Math.random()*(max-min+1)+min)+".html");
});
以上内容将随机选取从1到10的html页面
随机数代码礼貌:方济各回答问题您可以这样做:
$(function() {
var max = 10, min = 1;
$("#CONTENTS").load("contenuti/"+Math.floor(Math.random()*(max-min+1)+min)+".html");
});
以上内容将随机选取从1到10的html页面
随机数代码礼貌:方济各回答问题您可以这样做:
$(function() {
var max = 10, min = 1;
$("#CONTENTS").load("contenuti/"+Math.floor(Math.random()*(max-min+1)+min)+".html");
});
以上内容将随机选取从1到10的html页面
随机数编码礼貌:方济各对问题的回答fwiw
var max=10,min=1;Math.random()*(max-min+1)+min
可能返回8.37721847370267
Math.floor(Math.random()*(max-min+1)+min)
返回8
?@guest271314耶。Thanksfwiwvar max=10,min=1;Math.random()*(max-min+1)+min
可能返回8.37721847370267
Math.floor(Math.random()*(max-min+1)+min)
返回8
?@guest271314耶。Thanksfwiwvar max=10,min=1;Math.random()*(max-min+1)+min
可能返回8.37721847370267
Math.floor(Math.random()*(max-min+1)+min)
返回8
?@guest271314耶。Thanksfwiwvar max=10,min=1;Math.random()*(max-min+1)+min
可能返回8.37721847370267
Math.floor(Math.random()*(max-min+1)+min)
返回8
?@guest271314耶。谢谢