Html将div附加到另一个div中

Ran*_*ith 0 html javascript jquery

我对我的HTML设计有疑问.我有一个<div> ... </div>固定位置的部分.我希望<div></div>body标签内的任何地方重复使用它.

我尝试过使用jQuery和JavaScript与方法innerhtml('...'),after('...'),append('...').它有效,但我不想用引号解释100行,还有一件事.我希望不止一次<div></div>.

示例代码格式.

<html>
<head>
....
</head>

<body>
...
   <div id='includes_div'>       <!-- It hides on form load -->
      ...
      ...     <!-- having 100 of lines -->
   </div>

   <div id='div1'>
       <!-- want to include here -->
      ...
   </div>


   <div id='div2'>
       <!-- want to include here -->
      ...
   </div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

是用jQuery还是JavaScript?

小智 5

这应该工作:

var cont = $('#includes_div').html();
$('#div1').append(cont);
$('#div2').append(cont);
Run Code Online (Sandbox Code Playgroud)