javascript之firefox 不尊重 float 方向的 javascript 更改

xiaohuochai 阅读:248 2025-06-02 22:19:02 评论:0

此代码适用于除 firefox 之外的所有主要浏览器,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> 

这当然只是一个测试脚本 - 我提取了这个位只是为了看看是否有其他影响它。我什么也看不见。

蒂亚 阿德里安

请您参考如下方法:

http://www.iamseree.com/application-development/use-javascript-to-change-float-style

document.getElementById("CastPic").style.cssFloat="left"  

代码警告!!


标签:JavaScript
声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

关注我们

一个IT知识分享的公众号