在ASP.NET

时间:2015-09-01 03:50:09

标签: javascript jquery css asp.net

我有<map>,其中包含不同地区的图片。我需要在加载页面时更改不同热点的背景颜色。背景颜色信息存储在SQL Server表中。在加载页面时,我检索了颜色并将其存储在列表中。使用JavaScript,我需要更改特定<area>元素的背景颜色。

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Indicator_Color_Map.WebForm1" %>

<!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 runat="server">
    <title></title>
    <%--<style>
    area
    {
        background-color:Red;
    }
    </style>--%>
    <script type="text/javascript">
        function setColor() {
            document.getElementById("area1").style.background-color = "green";
        }
    </script>
</head>
<body onload="setColor()">
    <form id="form1" runat="server" >
    <div>
    <img src="jammu.jpg" alt="Planets" usemap="#planetmap" style="height: 434px; width: 369px">
    <map  id="map1" name="planetmap">   
  <area shape="rect" coords="0,0,82,126" href="" alt="Sun" id="area1"  >
  <area shape="circle" coords="90,58,3" href="" alt="Mercury" id="2">
  <area shape="circle" coords="124,58,8" href="" alt="Venus" id="3">
</map>
    </div>
    </form>
</body>
</html>

我尝试使用ImageMap控件,但我无法将样式应用于不同的坐标。

其他第三方控件是否有用?

1 个答案:

答案 0 :(得分:0)

使用style.backgroundColor代替style.background-color

document.getElementById("area1").style.backgroundColor = "green";