当前位置:编程学习 > C#/ASP.NET >>

动态生成层????

页面中有一个隐藏层div1,里面有画好控件。现在在页面放一个层div2,如何动态控制点击新建按钮后,隐藏层div1会显示在div2中,点击一次,生成一个,前一个生成的保存div2中,求教各位大神指点
<div2><div1></div1><div1></div1>...</div2> --------------------编程问答-------------------- 推荐用 underscore 的 js template 

通过 tempate parse 得出 html 后直接 append div 

其实也可以用 jquery clone --------------------编程问答--------------------
引用 1 楼 fangxinggood 的回复:
推荐用 underscore 的 js template 

通过 tempate parse 得出 html 后直接 append div 

其实也可以用 jquery clone


学习了。我一般用jquery的clone。 --------------------编程问答--------------------

  function addDIV() {
            var div= '<div1></div1>';
            document.getElementById('<div2>').insertAdjacentHTML("beforeEnd", div);
        }

貌似用js这样可以! --------------------编程问答--------------------

  function addDIV() {
            var div= '<div1></div1>';
            document.getElementById('div2的id').insertAdjacentHTML("beforeEnd", div);
        }


--------------------编程问答-------------------- $().append($().html()) --------------------编程问答-------------------- 代码要怎么实现 - -! --------------------编程问答--------------------
引用 2 楼 caozhy 的回复:
Quote: 引用 1 楼 fangxinggood 的回复:

推荐用 underscore 的 js template 

通过 tempate parse 得出 html 后直接 append div 

其实也可以用 jquery clone


学习了。我一般用jquery的clone。


clone 有一些问题,比如div 上的function。还是template好用。咔咔


<script type="text/template" id="gamesTemplate">
<@ for(var i=0; i<data.length; i++) { @>
<@ var item = data[i]; @>
<li style="padding:8px;">
<div style="height:60px;overflow-y:hidden;">
<img src="<@= item.pictureUrl @>" style="display:inline-block;width:140px;height:60px;"></img>
<div style="display:inline-block;font-size:15px;vertical-align:top;text-overflow:ellipsis;width:260px;">
<@= item.title@>
</div>
</div>

    <span style="float:right;font-size:10px;">
<a target="_self" href="initPublish.do?resendId=<@= item.id @>">再来一发</a> 
<@= new Date(item.startTime).format('MM-dd hh:mm') @>
</span>
</li>
<@ } @>
</script>

...

_.templateSettings = {
interpolate: /\<\@\=(.+?)\@\>/gim,
    evaluate: /\<\@(.+?)\@\>/gim,
    escape: /\<\@\-(.+?)\@\>/gim
};
var template = $(opt.listTemplateId).html();
var html = _.template(template, result.attributes.list, {variable: 'data'});
//console.log(html);
if (result.attributes.list.length <= 0) {
return;
}

$(opt.listBox).html(html);

--------------------编程问答-------------------- 除 --------------------编程问答--------------------
引用 7 楼 fangxinggood 的回复:
Quote: 引用 2 楼 caozhy 的回复:

Quote: 引用 1 楼 fangxinggood 的回复:

推荐用 underscore 的 js template 

通过 tempate parse 得出 html 后直接 append div 

其实也可以用 jquery clone


学习了。我一般用jquery的clone。


clone 有一些问题,比如div 上的function。还是template好用。咔咔


<script type="text/template" id="gamesTemplate">
<@ for(var i=0; i<data.length; i++) { @>
<@ var item = data[i]; @>
<li style="padding:8px;">
<div style="height:60px;overflow-y:hidden;">
<img src="<@= item.pictureUrl @>" style="display:inline-block;width:140px;height:60px;"></img>
<div style="display:inline-block;font-size:15px;vertical-align:top;text-overflow:ellipsis;width:260px;">
<@= item.title@>
</div>
</div>

    <span style="float:right;font-size:10px;">
<a target="_self" href="initPublish.do?resendId=<@= item.id @>">再来一发</a> 
<@= new Date(item.startTime).format('MM-dd hh:mm') @>
</span>
</li>
<@ } @>
</script>

...

_.templateSettings = {
interpolate: /\<\@\=(.+?)\@\>/gim,
    evaluate: /\<\@(.+?)\@\>/gim,
    escape: /\<\@\-(.+?)\@\>/gim
};
var template = $(opt.listTemplateId).html();
var html = _.template(template, result.attributes.list, {variable: 'data'});
//console.log(html);
if (result.attributes.list.length <= 0) {
return;
}

$(opt.listBox).html(html);



嗯嗯。
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,