鼠标移过,改变图片路径

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>鼠标移过,改变图片路径</title>
<style>
body,ul,li{margin:0;padding:0;}
body{background:#000;}
img{border:0;border-radius:3px;}
ul{list-style-type:none;}
#box{width:212px;border:5px solid #fff;overflow:hidden;zoom:1;background:#fff;border-radius:5px;margin:10px auto;padding:0 0 3px 3px;}
#box li,#box li img{float:left;width:50px;height:50px;}
#box li{margin:3px 3px 0 0;}
#box li.first{position:relative;}
#box li.first,#box li.first img{width:156px;height:156px;}
#box li.first div{position:absolute;top:0;left:0;width:156px;height:156px;display:none;opacity:0.5;filter:alpha(opacity=50);background:#fff url(img/loading.gif) 50% 50% no-repeat;}
</style>
<script type="text/javascript">
window.onload = function ()
{
    var oImg = document.getElementById("box").getElementsByTagName("img");
    var oDiv = document.getElementsByTagName("div")[0];
    for (var i = 1; i < oImg.length; i++)
    {
        oImg[i].onmouseover = function ()
        {                        
            var img = new Image();
            img.src = oImg[0].src = this.src.replace(/small/,"big");
            oDiv.style.display = "block";
            img.complete ? oDiv.style.display = "none" : (oImg[0].onload = function() {oDiv.style.display = "none"})
        }    
    }
};
</script>
</head>
<body>
<ul id="box">
    <li class="first"><img src="img/big_1.jpg"><div></div></li>
    <li><a href="javascript:;"><img src="img/small_1.jpg"></a></li>
    <li><a href="javascript:;"><img src="img/small_2.jpg"></a></li>
    <li><a href="javascript:;"><img src="img/small_3.jpg"></a></li>
    <li><a href="javascript:;"><img src="img/small_4.jpg"></a></li>
    <li><a href="javascript:;"><img src="img/small_5.jpg"></a></li>
    <li><a href="javascript:;"><img src="img/small_6.jpg"></a></li>
    <li><a href="javascript:;"><img src="img/small_7.jpg"></a></li>
    <li><a href="javascript:;"><img src="img/small_8.jpg"></a></li>
    <li><a href="javascript:;"><img src="img/small_9.jpg"></a></li>
    <li><a href="javascript:;"><img src="img/small_10.jpg"></a></li>
    <li><a href="javascript:;"><img src="img/small_11.jpg"></a></li>
</ul>
</body>
</html>
复选框(checkbox)全选/全不选/返选
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>复选框(checkbox)全选/全不选/返选</title>
<style>
body,dl,dt,dd,p{margin:0;padding:0;}
body{font-family:Tahoma;font-size:12px;}
label,input,a{vertical-align:middle;}
label{padding:0 10px 0 5px;}
a{color:#09f;text-decoration:none;}
a:hover{color:red;}
dl{width:120px;margin:10px auto;padding:10px 5px;border:1px solid #666;border-radius:5px;background:#fafafa;}
dt{padding-bottom:10px;border-bottom:1px solid #666;}
dt label{font-weight:700;}
p{margin-top:10px;}
</style>
<script type="text/javascript">
window.onload = function ()
{
    var oA = document.getElementsByTagName("a")[0];    
    var oInput = document.getElementsByTagName("input");
    var oLabel = document.getElementsByTagName("label")[0];
    var isCheckAll = function ()
    {
        for (var i = 1, n = 0; i < oInput.length; i++)
        {
            oInput[i].checked && n++    
        }
        oInput[0].checked = n == oInput.length - 1;
        oLabel.innerHTML = oInput[0].checked ? "全不选" : "全选"
    };
    //全选/全不选
    oInput[0].onclick = function ()
    {
        for (var i = 1; i < oInput.length; i++)
        {
            oInput[i].checked = this.checked            
        }
        isCheckAll()
    };
    //反选
    oA.onclick = function ()
    {
        for (var i = 1; i < oInput.length; i++)
        {
            oInput[i].checked = !oInput[i].checked
        }
        isCheckAll()
    };
    //根据复选个数更新全选框状态
    for (var i = 1; i < oInput.length; i++)
    {
        oInput[i].onclick = function ()
        {
            isCheckAll()
        }    
    }    
}
</script>
</head>
<body>
<dl>
    <dt><input type="checkbox" id="checkAll" /><label>全选</label><a href="javascript:;">反选</a></dt>
    <dd>
        <p><input type="checkbox" name="item" /><label>选项(一)</label></p>
        <p><input type="checkbox" name="item" /><label>选项(二)</label></p>
        <p><input type="checkbox" name="item" /><label>选项(三)</label></p>
        <p><input type="checkbox" name="item" /><label>选项(四)</label></p>
        <p><input type="checkbox" name="item" /><label>选项(五)</label></p>
        <p><input type="checkbox" name="item" /><label>选项(六)</label></p>
        <p><input type="checkbox" name="item" /><label>选项(七)</label></p>
        <p><input type="checkbox" name="item" /><label>选项(八)</label></p>
        <p><input type="checkbox" name="item" /><label>选项(九)</label></p>
        <p><input type="checkbox" name="item" /><label>选项(十)</label></p>
    </dd>    
</dl>
<center>1、切换全选/全不选文字;2、根据选中个数更新全选框状态;</center>
</body>
</html>

 

posted @ 2015-05-03 22:59  mayufo  阅读(342)  评论(0编辑  收藏  举报