永发信息网

使用JS来动态添加相同的一段HTML代码,如下的div组合

答案:1  悬赏:30  手机版
解决时间 2021-01-28 18:59
  • 提问者网友:临风不自傲
  • 2021-01-28 06:09
<div id="1option" style="width:800px;height:170px;display:block">
<div id="first">
<div style="width:800px;height:20px;background-color:#EDEDED;">
<div id="legend" style="float:left" ></div>
<div class="fa fa-times" id="close12" onclick="c('1option');" style="float: right;cursor:pointer;"></div>
<div class="fa fa-arrows-alt" id="d1toBig" onclick="c('seconddiv');" style="float:right;margin-right:5px" ></div>
<div class="fa fa-wikipedia-w" id="d1To7day" style="float:right;margin-right:5px;cursor:pointer"></div>
</div>
<div id="container" style="width:800px;height:150px;background-color:#FFFFFF"></div>
</div>

<div id="seconddiv" style="height:900px;width:1580px;z-index: 9999; display:none; position: fixed; left: 10px; top: 15px;background-color: #2E8B57">
<div class="fa fa-times" id="close12" onclick="c('seconddiv');" style="float: right;margin-right:40px;margin-top:7px;cursor:pointer;"></div>
<div id="newdiv1" style="width:1500px;height:700px;margin-left:40px;margin-top:30px"> </div>
</div>
</div>
js中的onclick方法是
function c(self){
$("#"+self).toggle();
}
最佳答案
  • 五星知识达人网友:纵马山川剑自提
  • 2021-01-28 07:24
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>RunJS</title>
    <script id="jquery_180" type="text/javascript" class="library" src="/js/sandbox/jquery/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
        function c(a, b) {
            var ap = a.parents("#1option");
            if (!b) {
                ap.toggle();
            } else {
                ap.find(b).toggle();
            }
        };
        $(function() {
            $(":button[value='添加']").click(function() {
                $("body").append($("textarea").val());
            });
        });
    </script>
</head>

<body>
    <input type="button" value="添加" />
    <textarea style="display:none;">
        <div id="1option" style="width:800px;height:170px;display:block">
            <div id="first">
                <div style="width:800px;height:20px;background-color:#EDEDED;">
                    <div id="legend" style="float:left">c</div>
                    <div class="fa fa-times" id="close12" onclick="c($(this));" style="float: right;cursor:pointer;">x</div>
                    <div class="fa fa-arrows-alt" id="d1toBig" onclick="c($(this),'#seconddiv');" style="float:right;margin-right:5px">s</div>
                    <div class="fa fa-wikipedia-w" id="d1To7day" style="float:right;margin-right:5px;cursor:pointer"></div>
                </div>
                <div id="container" style="width:800px;height:150px;background-color:#FFFFFF"></div>
            </div>
            <div id="seconddiv" style="height:900px;width:1580px;z-index: 9999; display:none; position: fixed; left: 10px; top: 15px;background-color: #2E8B57">
                <div class="fa fa-times" id="close12" onclick="c($(this),'#seconddiv');" style="float: right;margin-right:40px;margin-top:7px;cursor:pointer;"></div>
                <div id="newdiv1" style="width:1500px;height:700px;margin-left:40px;margin-top:30px"></div>
            </div>
        </div>
    </textarea>
</body>

</html>
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯