通过getElementById动态改变光标样式

2009-08-21 14:54:20 | 【
Hover your mouse here to see the current cursor setting!

本文通过getElementById动态改变广告的样式,点击按钮可以直接更换光标

查看全部代码 View Code

在网页<head>区添加以下代码

<script language="javascript" type="text/javascript"> 

function changeCursor(newCursor, elementId)
{

       document.getElementById(elementId).style.cursor = newCursor;

}
</script>


<style type="text/css">
<!--

body {
text-align:center;
}

div {
cursor:default;
background:#CCCCFF;
text-align:center;
border:1px #111 solid;
margin-top: 30px;
width:400px;
height:200px;
margin:auto;
padding-top:90px;
}

-->
</style>



在网页<body>区添加以下代码

<div id="id1">sharejs.com提醒您,把光标移动到此区域,查看光标样式<div>

<br>
<input style="padding-right:5px;" type="button" onclick="changeCursor('default', 'id1');" value="Default">
<input style="padding-right:5px;" type="button" onclick="changeCursor('pointer', 'id1');" value="Pointer">
<input style="padding-right:5px;" type="button" onclick="changeCursor('crosshair', 'id1');" value="Crosshair">
<input style="padding-right:5px;" type="button" onclick="changeCursor('progress', 'id1');" value="Progress">
<input style="padding-right:5px;" type="button" onclick="changeCursor('wait', 'id1');" value="Wait">
<input style="padding-right:5px;" type="button" onclick="changeCursor('help', 'id1');" value="Help">
<input style="padding-right:5px;" type="button" onclick="changeCursor('move', 'id1');" value="Move">


相关资源