61,115
社区成员
发帖
与我相关
我的任务
分享
<!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=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
window.onload = function() {
var btn = document.getElementById('btn');
/*
btn.onmouseover = function() {
this.style.backgroundColor = '#900';
this.style.color = '#FFF';
}
btn.onmouseout = function() {
this.style.backgroundColor = '';
this.style.color = '';
}
*/
//背景图
btn.onmouseover = function() {
this.style.backgroundImage = 'url(http://www.google.com.hk/intl/zh-CN/images/logo_cn.png)';
}
btn.onmouseout = function() {
this.style.backgroundImage = 'none';
}
//按下后改变样式
btn.onclick = function() {
this.style.backgroundImage = 'url(http://www.google.com.hk/intl/zh-CN/images/logo_cn.png)';
//重新绑定的monmouseover、onmouseout事件
this.onmouseover = function() { }
this.onmouseout = function() { }
}
}
</script>
</head>
<body>
<input type="button" id="btn" value="我是只按钮" />
</body>
</html>
<input type="button" value="移上来变色" onmouseover="this.style.backgroundColor='#ff0000';" onmouseout="this.style.backgroundColor='';">
<style>
input[type=button]{background-color:blue}
input[type=button]:hover,input[type=button]:active{background-color:red}
</style>
<input type="button" value="变脸的按钮" />
<!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=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
window.onload = function() {
var obj = document.getElementsByTagName('input');
for(var i = 0; i < obj.length; i ++) {
if (obj[i].type.toLowerCase() == 'button') {
obj[i].onmouseover = function() {
this.style.backgroundColor = '#900';
this.style.color = '#FFF';
}
obj[i].onmouseout = function() {
this.style.backgroundColor = '';
this.style.color = '';
}
}
}
}
</script>
</head>
<body>
<input type="button" value="我是只按钮" />
</body>
</html>
<!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=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
window.onload = function() {
var btn = document.getElementById('btn');
btn.onmouseover = function() {
this.style.backgroundColor = '#900';
this.style.color = '#FFF';
}
btn.onmouseout = function() {
this.style.backgroundColor = '';
this.style.color = '';
}
}
</script>
</head>
<body>
<input type="button" id="btn" value="我是只按钮" />
</body>
</html>
<button id="btn" style="background:#3F3">click me</button>
<script>
document.getElementById('btn').onmouseover = function(){this.style.background = '#3CF'}
document.getElementById('btn').onmouseout = function(){this.style.background = '#3F3'}
</script>