4-13.html

来自「Ajax的例子」· HTML 代码 · 共 49 行

HTML
49
字号
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>改变文字样式</title>
<style type="text/css">
.red{ color:red;
font-style:italic;
font-size:32;
}
.blue{color:blue;
font-size:36;
}
.black{color:black;
}
</style>

<script language="javascript">
function color(e)
{
	switch(e.srcElement.id){ //获得标记的id
		case "first":
			document.getElementById("first").className="red"; //修改文字的样式
			break;
		case "second":
			document.getElementById("second").className="blue";
			break;
	}
}

function clearText(e)
{
	switch(e.srcElement.id){
		case "first":
			document.getElementById("first").className="black";
			break;
		case "second":
			document.getElementById("second").className="black";
			break;
	}
}
</script>
</head>
<body>
<div id="first" onMouseOver="color(event);" onMouseOut="clearText(event);">我本将心照明月</div>
<br>
<div id="second" onMouseOver="color(event);" onMouseOut="clearText(event);">奈何明月照沟渠</div>
</body>
</html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?