Javascript 鼠标悬停按钮
Javascript Mouseover button
我想我已经接近做到这一点了,但是当用户将鼠标悬停在提交按钮上时,我不知道如何更改提交按钮的颜色,我也是新手javascript,所以任何帮助将不胜感激
这是我的代码:
<html>
<head>
<title>JavaScript</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script>
function getName(){
var name;
name = window.prompt("Enter your name", "");
greeting = "User Information for " + name;
var txt= document.getElementById('txtWelcome');
txt.innerHTML=greeting;
}
function over() {
document.getElementById("Submit").style.background = 'Blue';
}
function out() {
document.getElementById("Submit").style.background = 'Yellow';
}
</script>
</head>
<body onload="getName()">
<form class="basic_form">
<h1 id="txtWelcome"></h1>
<p>Please input your login details</p>
<fieldset>
<label class="form_labels">Username:</label>
<input class="form_fields" type="text" name="username"><br>
<label class="form_labels">E-Mail:</label>
<input class="form_fields" type="email" name="email"><br>
<label class="form_labels">Password:</label>
<input class="form_fields" type="password" name="password">
<input class="form_buttons" type="Submit" value="Submit"><br>
</fieldset>
</form>
</body>
这是javascript解决方案:
var submitButton = document.getElementById('submit');
submitButton.addEventListener('mouseover', function() {
this.style.backgroundColor='blue';
});
submitButton.addEventListener('mouseout', function() {
this.style.backgroundColor='yellow';
});
https://jsfiddle.net/hsxdkkp6/
但是为什么不直接使用 css呢?
input[type=submit]:hover {
background-color: red;
}
https://jsfiddle.net/jkkj8dvt/
相关文章:
- 鼠标悬停事件影响列表中所有行中的按钮,而不仅仅是特定按钮
- Flexslider导航按钮在悬停时不可见,带有橙色框
- Facebook登录按钮悬停框
- 鼠标悬停时更改按钮的 CSS
- 将鼠标悬停在按钮上会导致另一个按钮悬停在上面
- 弹出 Div 显示在按钮悬停上
- 按钮悬停效果在不同的 Z 索引上
- 按钮悬停时触发弹出窗口
- 鼠标离开并不总是在我的按钮悬停时触发
- 使用按钮悬停使元素更改颜色
- 交叉褪色提交按钮悬停
- 自定义css单选按钮悬停效果
- CSS按钮:悬停,禁用,然后用javascript重新启用
- 图像与动画CSS +提交按钮悬停
- 如何禁用google +1(+1)按钮's悬停气泡
- Jquery悬停-允许悬停在按钮悬停的另一个DIV上
- 字体真棒社交媒体按钮悬停效果
- Twitter喜欢按钮悬停效果
- 定制';Pin it ';按钮悬停(我不使用博客或WordPress)
- jQuery隐藏li元素,然后在按钮悬停时淡入