<html>
<head>
<script language = "javascript" type = "text/javascript" >
function marry()
{
this.x = 0;
this.y = 0;
this.move = function (derect){
switch(derect)
{
case 0 : window.alert("向上走");
var marry2 = document.getElementById(sb);
window.alert(sb.s2.left);
break;
case 1 : window.alert("向右走");
break;
case 2 : window.alert("向下走");
break;
case 3 : window.alert("向左走");
break;
}
}
//document.getElementById(id) DOM对象 对要进行获取的元素配一个ID 通过 document.getElementById(id)来获得这个元素
//这里 因为我们要改变 Img的left和right 首先要对img进行获取
}
var marry1 = new marry();
function ps(derect)
{
switch(derect)
{
case 0 : marry1.move(0);
break;
case 1 : marry1.move(1);
break;
case 2 : marry1.move(2);
break;
case 3 : marry1.move(3);
break;
}
}
</script>
<style type=text/css>
body{
border:1px solid red;
margin:0 auto;
width:1000px;
}
.s1
{
width:800px;
height:300px;
background-color:red;
position:absolute;
margin:0 auto;
}
.s2
{
width :50px;
height:30px;
position:absolute;
left:200px;
}
.table1
{
border : 1px solid red ;
width:500px;
height:200px;
margin:0 auto;
}
.s3
{
position:absolute;
top:300px;
left:200px;
}
</style>
</head>
<body>
<div class = s1>
<img id ="sb" src = images/1.jpg class = s2 />
</div>
<div class = s3 >
<table class = table1>
<tr colspan = 3><td>游戏键盘</td></tr>
<tr><td>****</td><td><input type = button value = ↑ onclick = ps(0) /></td><td>****</td></tr>
<tr><td><input type = button value = ← onclick = ps(3) /></td><td>****</td><td>****</td></tr>
<tr><td>****</td><td>****</td><td><input type = button value = → onclick = ps(1) /></td></tr>
<tr><td>****</td><td><input type = button value = ↓ onclick = ps(2) /></td><td>****</td></tr>
</table>
</div>
</body>
</html>
问 我如果把s2 里面的样式用style写到img里面,能把sb.s2.left的值提取出来 但是用类选择器写的话就提不出来了 ,请问是哪里出问题了呀
小草1434
宝慕林2233867
super_mb
Instant
相关分类