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

标签 javascript firefox css-float

此代码适用于除 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 - firefox 不尊重 float 方向的 javascript 更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9290989/

相关文章:

javascript - 检测 Bootstrap 模式以更改按键输入的目的地

javascript - 如何循环遍历表 td 并在 jquery 中返回一个字符串?

javascript - 使用 Math.random() 生成均匀分布

javascript - 如何动态添加带有文本框的表格行?

safari 中的 css 颜色渲染不同

html - CSS 菜单溢出?

selenium - 在 colab 中安装并运行 selenium 浏览器

css - Firefox 2.0 中的自动换行

html - CSS 顶栏 : vertical separator wraps the content of the bar

css - 列表项不会彼此相邻出现