Home >Web Front-end >HTML Tutorial >How to use variable _html/css_WEB-ITnose in DIV
There is a piece of code, roughly as follows:
87324767b0f31e74d7c0597907cddf10 … 16b28748ea4df4d9c2150843fecfba68
06e5b60d99e2d4ac140d96761bc536f7 … 16b28748ea4df4d9c2150843fecfba68
fe3d3d91979a608bca3dc3b4dd0fb5d6 … 16b28748ea4df4d9c2150843fecfba68
…
Because there are many layers, I want the numbers after the div and class to use variables and implement loops. How to implement it in html file?
1e0c4de43badeaa825236bebe32b838f
.....
16b28748ea4df4d9c2150843fecfba68
Add a div to the periphery, use javascript to pass through the div, loop the internal div, and then operate
Pure HTML can't do it
There are three ideas for using js.
One is document.write
Two is innerHTML
Three is createElement
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script><script type="text/javascript"> $(function(){ $("#abv").click(function(){ for(var i=1;i<=$("div").length-1;i++){ $("#div"+i).html(i); } }); })</script><input type="button" id="abv" value="测试用按钮"/><div id="kkk"> <div id="div1" class="class1">`````</div> <div id="div2" class="class2">`````</div> <div id="div3" class="class3">`````</div></div>
1. Use descendant code to implement
whether it is asp. Net/asp/jsp all have for loops. The advantage of this is that even if the client does not support js, it can still display DIV
2. Use js to implement
for(var i=1;i55620ea1265e5242e677633fd0b020d116b28748ea4df4d9c2150843fecfba68').append("body");
}
for(var i=1;i842f50a55559fb4bbc1ded751ffa1e4ed4e6ef3935d870d31c81823c096b9b03').appendTo("body");
}