动态添加内容 insertAdjacentText()方法和insertAdjacentHTML方法

来源:互联网 发布:跑步软件排名 编辑:程序博客网 时间:2024/06/05 03:48
<html><head><title>中国风</title><meta http-equiv="Content-Type" content="text/html; charset=gb2312"></head><script language="JavaScript">function iat(){p1.insertAdjacentText("afterBegin","杜甫");}function iah(){//var obj=document.getElementById("p1");var str = '<font size="10px" color="blue">恨别</font>';p1.insertAdjacentHTML("beforeBegin",str);}</script><body><table><tr align="center"><td><pre id="p1"><br>洛城一别四千里,胡骑长驱五六年。草木变衰行剑外,兵戈阻绝老江边。思家步月清宵立,忆弟看云白日眠。闻道河阳近乘胜,司徒急为破幽燕。</pre><br><input type="button" value="诗人" onclick="iat()"><input type="button" value="诗名" onclick="iah()"></td></tr></table></body></html>

原创粉丝点击