<script>
function amo()
{
document.write("<div class='x'>eee</div>")
document.write("<div class='x'>eee</div>")
document.write("<div class='x'>eee</div>")
}
</script>
<style>
.x{width:50px;height:50px;background-color:red;}
</style>
<input type=button onclick='amo()' value='fff'>
因为


document.write
会重写整个html
的内容原先是这样的
而你点击之后,页面源码变成了这样
也就是只有
amo
里面的内容了你的
style
样式都被覆盖替换掉了