如何正确设置单个鼠标悬停按钮的ID

时间:2013-05-17 09:06:45

标签: javascript html popup onmouseover onmouseout

我有一列按钮,必须与第一个按钮做同样的事情,但有自己的个人照片。如何设置ID以便没有故障?现在我有三个按钮设置,但他们以某种方式复制了相同的名称(他们都说移动快速洗)!这是我到目前为止http://ultimatefinishdetailing.com/Services.html

HTML :(在图片按钮上张贴HTML)

<STYLE MEDIA="screen" TYPE="text/css">
.pop-up {
    height: 100px;
    width: 100px;
    margin-right: -100px;
    margin-top: -100px;
    position:absolute;
right:-50px;
top:75px;
}
.button {
      width:300px;
      height:21px;
      display:block; background-image:url(images/button_ufad4.jpg);
      position:absolute;
}
</style>
<a href="" class="button" onmouseover="javascript:ShowImage('images/InteriorandExteriorDetailing.jpg')" onmouseout="javascript:HideImage()"></a>

<div id="popup" class="pop-up">
   <img id="popupImage" alt="" /> 
</div>

使用Javascript:

<script type="text/javascript">
    function ShowImage(src)
    {
        var img = document.getElementById('popupImage');
        var div = document.getElementById('popup');
        img.src = src;
        div.style.display = "block";
    }
    function HideImage()
    {
        document.getElementById('popup').style.display = "none";
    }
</script>

1 个答案:

答案 0 :(得分:0)

想出来!为每个按钮使用不同的id,类。下面的示例是一个按钮,为每个其他按钮更改id / classes的数量

HTML:1。CSS(样式)必须拥有自己的ID EX :(。pop-up1,2,3等; .button1,2,3等)       2. <A>(锚标记)必须有自己的id和类EX :( ID = BUTTON1,2,3等; CLASS = button1,2,3等)       3. div标签<div>必须拥有它自己的id,类,图像ID EX :( DIV ID =“popup1”,CLASS =“pop-up1”,IMG ID =“popupImage1

<STYLE MEDIA="screen" TYPE="text/css">
.pop-up1 {height: 100px;width: 100px;margin-right:-100px;margin-top:-100px;position:absolute;display:none;right:-50px;top: 75px;opacity:.7;z-index: 1}
.button1 {
      width:300px;
      height:21px;
      display:block; background-image:url(images/button_ufad4.gif);
      position:absolute;
}
.button1:hover {    background-position:left 43px;
}
</STYLE>
<A ID="BUTTON1" HREF="" CLASS="button1" ONMOUSEOVER="javascript:ShowImage('images/ufad2servicesexteriorandinteriordetailing.gif')" ONMOUSEOUT="javascript:HideImage()"></A>
<DIV ID="popup1" CLASS="pop-up1">
<IMG ID="popupImage1"> 
</DIV>

使用Javascript:

<script type="text/javascript">
    function ShowImage(src)
    {
        var img= document.getElementById('popupImage1');
        var div= document.getElementById('popup1');
        img.src=src;
        div.style.display="block";
    }
    function HideImage()
    { document.getElementById('popup1').style.display ="none";}
</script>