这个代码适用于所有主流浏览器,除了firefox,它说它完成了我的要求,但事实并非如此。这让我疯狂。这是完整的html,css和javascript:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" >
<html>
<head>
<style type=text/css>
.CastPic
{
position : relative;
top : +0px;
width : 250px;
height : 250px;
padding-top : 25px;
padding-left : 25px;
padding-right : 25px;
padding-bottom : 25px;
background-image : url('Cast photos/Fiona Colquhoun.jpg');
background-color : ivory;
background-repeat : no-repeat;
background-position : center;
cursor : pointer;
border-style : solid;
border-width : 12px;
border-color : green;
float : left;
}
</style>
<script language="JavaScript" type="text/JavaScript">
function toggle()
{
if (document.getElementById("CastPic").style.float =="right")
{
document.myForm.msg.value = "float is right"
document.getElementById("CastPic").style.float="left"
document.getElementById("CastPic").style.borderColor="red"
}
else
{
document.myForm.msg.value = "float is left"
document.getElementById("CastPic").style.float="right"
document.getElementById("CastPic").style.borderColor="blue"
}
document.myForm.msg.value = 'float is now ' + document.getElementById("CastPic").style.float
}
</script>
</head>
<body>
<div class="CastPic" id="CastPic"></div>
<form name="myForm" enctype="application/x-www-form-urlencoded">
<input type="text" name="msg" value="" size=65>
<input type="button" value="Switch" onClick="toggle()">
</form>
</body>
</html>
这当然只是一个测试脚本 - 我提取这个位只是为了看看是否还有其它因素影响了它。我看不到任何东西。
蒂亚 阿德里安
答案 0 :(得分:8)
http://www.iamseree.com/application-development/use-javascript-to-change-float-style
document.getElementById("CastPic").style.cssFloat="left"
代码提醒!!