
.box1{
width: 600px
height:300px
border: 6px solid #bb0000
}
h1{
border-bottom: 1px solid green
}
</style>
<div class="box1">
点击改变内容
</div>
<script src="http://code.jquery.com/jquery.js"></script>
<script>
$('.box1').click(function(event) {
$(this).html('=========================================================这是新添贴==================================')
})
</script>
所谓动态写入方法就是源文件代码中原来没有内容或者需要重新改变此处的要显示的文字或内容,需要用JavaScript代码来实现。动态写入是一种很常见常用的方法。1、用innerHTML写入html代码:
<div id="abc"></div>
<script>document.getElementById("abc").innerHTML="要写入的文字或内容"</script>
2、appendChild() 方法:
<ul id="myList"><li>Coffee</li><li>Tea</li></ul>
<button onclick="myFunction()">点击向列表添加项目</button>
<script>
function myFunction(){
var node=document.createElement("LI")
var textnode=document.createTextNode("Water")
node.appendChild(textnode)
document.getElementById("myList").appendChild(node)
}
</script>
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)