js生成p隔行颜色不一样
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script type="text/javascript">
// 生成100个p元素,隔行变色
window.onload = function(){
for(var i = 1; i <= 100; i++){
if(i % 2 ==0){
document.write('<p style="background: #00ADEF;">我是第:'+i+'个p</p>');
//document.body.innerHTML += '<p style="background:#00ADEF;">我是第'+ i + '</p>';
}else{
document.write('<p>我是第:'+i+'个p</p>');
//document.body.innerHTML += '<p>我是第'+ i + '</p>';
}
}
}
</script>
</head>
<body>
</body>
</html>
本文来自博客园,作者:JackieDYH,转载请注明原文链接:https://www.cnblogs.com/JackieDYH/p/17634844.html