Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 如何将随机html页面从文件夹加载到div中_Jquery_Html - Fatal编程技术网

Jquery 如何将随机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页面(从包含所有页面的文件夹)加载到div中的正确方法。 这就是我现在所做的:

<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耶。Thanksfwiw
var max=10,min=1;Math.random()*(max-min+1)+min
可能返回
8.37721847370267
Math.floor(Math.random()*(max-min+1)+min)
返回
8
?@guest271314耶。Thanksfwiw
var max=10,min=1;Math.random()*(max-min+1)+min
可能返回
8.37721847370267
Math.floor(Math.random()*(max-min+1)+min)
返回
8
?@guest271314耶。Thanksfwiw
var max=10,min=1;Math.random()*(max-min+1)+min
可能返回
8.37721847370267
Math.floor(Math.random()*(max-min+1)+min)
返回
8
?@guest271314耶。谢谢