3

I am not an experienced javascript, css coder so I would appreciate as much help as possible. I've read some other posts for more understanding; they mentioned jquery but I'm not sure how to go about that either.

I have a code that was generated for me with a program. I need to change about 7 image buttons (not links) href rollovers into td onclick. Thanks so much in advance. Here is my current code:

Within the head -

<script type="text/javascript">
function newImage(arg) {
if (document.images) {
    rslt = new Image();
    rslt.src = arg;
    return rslt;}
}

function changeImages() {
if (document.images && (preloadFlag == true)) {
    for (var i=0; i<changeImages.arguments.length; i+=2) {
        document[changeImages.arguments[i]].src = changeImages.arguments[i+1];}
}

}

var preloadFlag = false;
function preloadImages() {
if (document.images) {
    info_savantgenius_com_over = newImage("images/info@savantgenius.com-over.gif");
    About_over = newImage("images/About-over.gif");
    Artist_over = newImage("images/Artist-over.gif");
    Portfolio_over = newImage("images/Portfolio-over.gif");
    Pricing_over = newImage("images/Pricing-over.gif");
    Order_over = newImage("images/Order-over.gif");
    Contact_over = newImage("images/Contact-over.gif");
    About_over033 = newImage("images/About-over-33.gif");
    Artist_over035 = newImage("images/Artist-over-35.gif");
    Portfolio_over037 = newImage("images/Portfolio-over-37.gif");
    Pricing_over039 = newImage("images/Pricing-over-39.gif");
    Order_over041 = newImage("images/Order-over-41.gif");
    Contact_over043 = newImage("images/Contact-over-43.gif");
    preloadFlag = true;}

}


Within the body -

<td colspan="2">

<a href="mailto:info@savantgenius.com"
            onmouseover="changeImages('info_savantgenius_com', 'images/info@savantgenius.com-over.gif'); return true;"
            onmouseout="changeImages('info_savantgenius_com', 'images/info@savantgenius.com.gif'); return true;"
            onmousedown="changeImages('info_savantgenius_com', 'images/info@savantgenius.com-over.gif'); return true;"
            onmouseup="changeImages('info_savantgenius_com', 'images/info@savantgenius.com-over.gif'); return true;">
            <img name="info_savantgenius_com" src="images/info@savantgenius.com.gif" width="220" height="49" border="0" alt=""></a></td>
4

2 回答 2

1

您可以简单地使用document.getElementById()而不是 document[changeImages.arguments[i]]

function changeImages() {
    if (document.images && (preloadFlag == true)) {
      for (var i=0; i < arguments.length; i+=2) {
        document.getElementById(arguments[i]).src = arguments[i+1];
      }
    }
}
于 2011-11-07T18:09:49.087 回答
0

你可以使用这个:

http://api.jquery.com/hover/

所以它会给你类似的东西:

$("#mytd1").hover(function(){$(this).css("background-image", [PUT THE NEW IMAGE PATH HERE])});

[将新的图像路径放在这里]类似“url('image.jpg')”的东西

你需要包括 jquery 库

于 2011-11-07T18:02:58.817 回答