日期:2014-05-16 浏览次数:20383 次
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
var closeObj=document.getElementById("gc");
var floatObj=document.getElementById("gc");
function test(){
alert(closeObj);
alert(floatObj);
}
</script>
</head>
<body>
<div id="tc"><img src="images/2.jpg"/></div>
<div id="gc" onclick="test()"><img src="images/1-1.bmp"/></div>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
<div id="tc"><img src="images/2.jpg"/></div>
<div id="gc" onclick="test()"><img src="images/1-1.bmp"/></div>
</body>
</html>
<script type="text/javascript">
window.onload=function(){
var closeObj=document.getElementById("gc");
var floatObj=document.getElementById("gc");
function test(){
alert(closeObj);
alert(floatObj);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
window.onload=function(){
closeObj=document.getElementById("gc");//注意:此处定义不要用var,要定义为全局变量