Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.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
Javascript 如何让一个div包含多个div它可能是4-6-8我如何使用Jquery在页面加载中适应它们_Javascript_Jquery_Html_Css - Fatal编程技术网

Javascript 如何让一个div包含多个div它可能是4-6-8我如何使用Jquery在页面加载中适应它们

Javascript 如何让一个div包含多个div它可能是4-6-8我如何使用Jquery在页面加载中适应它们,javascript,jquery,html,css,Javascript,Jquery,Html,Css,如何使一个div包含多个div?可能是4-6-8。如何使用Jquery在页面加载时调整它们 <div id="main"> <div class="box"></div> <div class="box"></div> <div class="box"></div> <div class="box"></div> </div> 我想创建一个jquery函数,通过在

如何使一个div包含多个div?可能是4-6-8。如何使用Jquery在页面加载时调整它们

<div id="main">
 <div class="box"></div>
 <div class="box"></div>
 <div class="box"></div>
 <div class="box"></div>
</div>


我想创建一个jquery函数,通过在页面加载时捕捉子div和父div的高度和宽度,使其适合于子div和父div。

我想尝试一下,希望您想要的是您真正想要的。我假设您希望在页面加载后将动态数量的
元素插入
元素。如果是这样的话,这应该是可行的:

HTML


jQuery

function createBoxes(numberOfBoxes) {
    var $box = $('<div/>').addClass('box');
    var $container = $('#main');
    for(var i = 1; i <= numberOfBoxes; i++) {
        $container.append($box.clone().text(i));   
    }
}

$(function() { // calls createBoxes() when the DOM is ready
               // shortened version of $(document).ready(function() {
    createBoxes(4);
});
函数CreateBoxs(NumberOfBox){
var$box=$('').addClass('box');
var$container=$(“#main”);

对于(var i=1;i)来说,你问的问题一点也不清楚,请说得更具体一些。问题中的HTML是你在页面加载时已经拥有的,还是你希望得到的结果的一个例子?@jackJoe根据Wiktionary:“(古语)第二人称单数简单现在形式的冲动”。我想他们可能是想说“插入”,但我只能猜测。@AnthonyGrist我也在Wiktionary上读到过,听起来这是一个历史性的问题。我如何获取儿童节目的id?我可以对其执行操作吗?请说得更清楚一点,我只想在我的html代码中添加新的儿童div,不想担心其他事情。应该只设置所有儿童div的高度和宽度。请也考虑这个。
function createBoxes(numberOfBoxes) {
    var $box = $('<div/>').addClass('box');
    var $container = $('#main');
    for(var i = 1; i <= numberOfBoxes; i++) {
        $container.append($box.clone().text(i));   
    }
}

$(function() { // calls createBoxes() when the DOM is ready
               // shortened version of $(document).ready(function() {
    createBoxes(4);
});