| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1508 人关注过本帖
标题:var imgObj = document.getElementById(linkObj.className);中classname 取 ...
只看楼主 加入收藏
sunbenlong
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2009-8-21
收藏
 问题点数:0 回复次数:0 
var imgObj = document.getElementById(linkObj.className);中classname 取的值是什么,大家帮帮我看
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html xmlns="http://www.
<head>
    <title>Multiple Links, Single Rollover</title>
    <script src="script05.js" language="javascript" type="text/javascript"></script>
</head>
<body bgcolor="#EECC99">
    <img src="images/DaVinci.jpg" width="144" height="219" alt="DaVinci" align="right" hspace="50" />
    <img src="images/leoText.gif" width="375" height="26" alt="Leonardo's Inventions" />
    <a href="flyPage.html" class="textField" id="flyer"><img src="images/flyer.gif" width="293" height="165" border="0" alt="Flying Machine" vspace="10" id="flyerImg" /></a><br clear="right" />
    <img src="images/bg.gif" width="208" height="27" id="textField" alt="Text Field" align="right" vspace="20" />
    <a href="tankPage.html" class="textField" id="tank"><img src="images/tank.gif" width="325" height="92" border="0" alt="Tank" id="tankImg" /></a><br />
    <a href="heliPage.html" class="textField" id="helicopter"><img src="images/helicopter.gif" width="224" height="160" border="0" alt="Helicopter" id="helicopterImg" /></a>

<p>多个链接触发一个翻转器</p>
</body>
</html>

下面为script05.js
window.onload = rolloverInit;

function rolloverInit() {
    for (var i=0; i<document.links.length; i++) {
        var linkObj = document.links[i];
        
        if (linkObj.className) {                    //因为id必须是唯一的,,我们要使用class属性寻找链接对像classname
            var imgObj = document.getElementById(linkObj.className);
            
            if (imgObj) {
                setupRollover(linkObj,imgObj);
            }
        }
    }
}

function setupRollover(thisLink,textImage) {
    thisLink.imgToChange = textImage;
    thisLink.onmouseout = rollOut;
    thisLink.onmouseover = rollOver;    
    
    thisLink.outImage = new Image();
    thisLink.outImage.src = textImage.src;

    thisLink.overImage = new Image();
    thisLink.overImage.src = "images/" + thisLink.id + "Text.gif";
    
}

function rollOver() {
    this.imgToChange.src = this.overImage.src;
}

function rollOut() {
    this.imgToChange.src = this.outImage.src;
}
搜索更多相关主题的帖子: javascript class classname 
2009-08-21 13:46
快速回复:var imgObj = document.getElementById(linkObj.className);中classna ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016550 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved