点击按钮更换文字及样式

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新建网页 1</title>
<style type="text/css">
.class1{
	color:red
}
.class2{
	color:blue
}
</style>
</head>
<body>
<input type="button" class="class1" value="点我" id="a1">
<script type="text/javascript">
window.onload = function(){
	var obj = document.getElementById("a1");
	obj.onclick = function(){
		obj.className = (obj.className == "class1"?"class2":"class1");
		obj.value = (obj.value == "点我"?"我被点了":"点我");
	}
}
</script>
</body>
</html>
原文地址:https://www.cnblogs.com/caobiin/p/7661078.html