鼠标悬停时更改按钮的bground颜色 [英] change bground color of button when mouseover

查看:129
本文介绍了鼠标悬停时更改按钮的bground颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<script type="text/javascript" language="javascript">

      window.onload = function() {
          document.getElementById("Button6").onmouseover = function()
          {
              this.style.backgroundColor = "#9933ff";
          }

          document.getElementById("Button6").onmouseout = function()
          {
              this.style.backgroundColor = "#9999ff";
          }
      }


  </script>



此代码仅适用于一个按钮

如何让代码适用于许多按钮

BR


this code is work for one button only
how to make that code work for many buttons
B.R

推荐答案

这是你做的:你首先用一种颜色为你的按钮着色然后,立即用一些不同的颜色着色。当然,你只能看到最新的背景颜色。



相反,你需要处理一些事件。使用jQuery库非常方便。以下是您的完整代码示例,请尝试:

Here is what you do: you first color your button in one color and then, immediately, color it in some different color. Naturally, you can see only the latest background color.

Instead, you need to handle some events. It's very convenient to do with jQuery library. Here is a complete code sample for your, please try:
<html>
<head>
    <title></title>
    <script type="text/javascript" src="scripts/jquery-1.7.1.min.js"></script>
    <style type="text/css"><!--
        button.normal { backgroundColor:"#9933ff"; }
        botton.mouseOver { backgroundColor:"##9999ff"; }
    --></style>
</head>
<body>

    <button class="normal" id="myButton">Some text</button>

    <script type="text/javascript">


(document).ready(function(){
buttonElement =
(document).ready(function() { buttonElement =


(#myButton);
imageElement.hover(//接受两个函数
function(){//鼠标遍历:
("#myButton"); imageElement.hover( // accepts two functions function() { // mouse goes over:


这篇关于鼠标悬停时更改按钮的bground颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆