Skip to content

Instantly share code, notes, and snippets.

@1901
Created April 25, 2012 03:48
Show Gist options
  • Save 1901/2486098 to your computer and use it in GitHub Desktop.
Save 1901/2486098 to your computer and use it in GitHub Desktop.
使用JS+Html动态修改显示内容
<html>
<SCRIPT LANGUAGE='JavaScript'>
function addline(text, textColor) {
var newDiv = document.createElement('DIV');
newDiv.style.color = textColor;
newDiv.innerHTML = text;
document.getElementById('contentDiv').appendChild(newDiv);
window.scroll(0,window.document.body.scrollHeight);
}
function clearContent() {
var cnt = document.getElementById('contentDiv');
while(cnt.children.length > 0) {
cnt.removeChild(cnt.children[0]);
}
}
</SCRIPT>
<style>
a {color:#12f569; }
div {padding-top:2px;}
</style>
<body style='background-color:#000000; color:#ffffff; font-size:13px; font-family:Helvetica; margin-left:0px; margin-top:0px;'>
<input id="a" type='button' value='增加一行' onclick="addline('aaaaaaa<a href=\'#\'>aaa</a>aaaaaaa','#ff0000');" />
<input id="b" type='button' value='清除内容' onclick="clearContent();" />
<div id='contentDiv' width='400'></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment