Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.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小部件附加到容器_Jquery_Jquery Ui_Jquery Widgets - Fatal编程技术网

将多个jquery小部件附加到容器

将多个jquery小部件附加到容器,jquery,jquery-ui,jquery-widgets,Jquery,Jquery Ui,Jquery Widgets,我目前正在尝试将多个小部件附加到一个容器中 $( "#addbutton" ).click( function() { newid++; $("#designspace").append($("<div></div>").mywigdet({id:newid,top:100,left:100,width:100,height:100,color:"blue",text:"Hello"})); }); $(“#添加按钮”)。单击(函数(

我目前正在尝试将多个小部件附加到一个容器中

$( "#addbutton" ).click( function() {  
    newid++;
    $("#designspace").append($("<div></div>").mywigdet({id:newid,top:100,left:100,width:100,height:100,color:"blue",text:"Hello"}));        
});
$(“#添加按钮”)。单击(函数(){
newid++;
$(“#设计空间”).append($(“”).mywigdet({id:newid,top:100,left:100,width:100,color:“blue”,text:“Hello”});
});
通过这种方式,我需要创建一个div,然后将小部件添加到该div中

 ...
 this._container = $('<div class="label-container" id="' + newid +'" style="position:relative; border:1px solid black;"></div>').appendTo(this.element);
 this._setOptions({
      'top': this.options.top,
      'left': this.options.left,
      'width': this.options.width,
      'height': this.options.height,
      'color': this.options.color,
      'text': this.options.text
 });
 ...
。。。
this._container=$('').appendTo(this.element);
这是一个选项({
“top”:this.options.top,
“left”:this.options.left,
“宽度”:this.options.width,
“高度”:this.options.height,
“颜色”:this.options.color,
“text”:this.options.text
});
...
当它工作时,会在另一个容器中创建一个容器

但由于我的WIDGET中有相对定位代码,此方法阻止它工作,因为空白容器div位置是父级。p> 我可以将position内容移动到container DIV中,但这会降低使用小部件的灵活性


有没有更好的方法可以在不创建子容器的情况下将多个小部件添加到一个容器中?

我以前没有真正使用过jquery小部件。我认为你的问题是:

this._container = $('<div class="label-container" id="' + newid +'" style="position:relative; border:1px solid black;"></div>').appendTo(this.element);
编辑:我建议用另一个css类替换样式属性


谢谢,添加和编辑原始div已经完成了这一任务。
$(this.element).attr('id',newid);

$(this.element).addClass('label-container');
...