Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/90.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—在另一个div中相邻添加两个div的语法_Jquery_Html - Fatal编程技术网

jquery—在另一个div中相邻添加两个div的语法

jquery—在另一个div中相邻添加两个div的语法,jquery,html,Jquery,Html,我无法使jquery语法正常工作,以便可以向动态生成的每个父div追加1个(或更多)子div 下面是生成10行(div)字母的工作代码 var alphabet = new Array('A','B','C','D','E','F','G','H','I','J'); $(function() { for(i=0; i<10; i++) { $('<div/>', { id: 'foo', 'class': 'letters',

我无法使jquery语法正常工作,以便可以向动态生成的每个父div追加1个(或更多)子div

下面是生成10行(div)字母的工作代码

var alphabet = new Array('A','B','C','D','E','F','G','H','I','J');
$(function() {
    for(i=0; i<10; i++) {
         $('<div/>', {
    id: 'foo',
    'class': 'letters',
    text: alphabet[i],
    css: {  

        'padding-left': '5px',
        'background-color': 'fff',
        'overflow': 'hidden',
        'height': '22px',
        'width': '745px',
    },  
}).appendTo('div#container');
    }
});
var alphabet=新数组('A'、'B'、'C'、'D'、'E'、'F'、'G'、'H'、'I'、'J');
$(函数(){

对于(i=0;i那么,在每个div中添加另一个div,您可以简单地

$(function() {
    for(i=0; i<10; i++) {
         var otherDiv = $('<div/>');
           var  alphabetDiv =  $('<div/>', {
    id: 'foo',
    'class': 'letters',
    text: alphabet[i],
    css: {  

        'padding-left': '5px',
        'background-color': 'fff',
        'overflow': 'hidden',
        'height': '22px',
        'width': '745px',
    },  
   });
   otherDiv.appendTo(alphabetDiv);
  alphabetDiv.appendTo('div#container');
    }
});
$(函数(){

对于(i=0;我能告诉我们错误是什么吗?这样可以更快地找到问题。谢谢Nichola,我使用了其他人的代码,但不理解语法,谢谢你给出了一个很好的示例。