通过ID来获取HTML元素
·通过ID来获取HTML元素:document.getElementById("aaa")
·设置HTML的隐藏:document.getElementById("aaa").style.display = "none"
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>动态改变文本</title>
<script language="javascript" type="text/javascript">
function change()
{
document.getElementById("text").innerHTML = "<b>欢迎</b>来到北京!!!";
}
function hideText()
{
document.getElementById("text").style.display = "none";
}
function showText()
{
document.getElementById("text").style.display = "";
}
</script>
</head>
<body>
<p id="text">welcome to beijing!!!</p>
<form id="form1" name="form1" method="post" action="">
<p>
<input type="button" name="button" id="button" value="给我变成中文!!!" onclick="change();" />
</p>
<p>
<input type="button" name="button2" id="button2" value="隐藏文字" onclick="hideText();" />
</p>
<p>
<input type="button" name="button3" id="button3" value="显示文字" onclick="showText();" />
</p>
</form>
</body>
</html>
浙公网安备 33010602011771号