有没有在Javascript中设置style.float的跨浏览器方式? [英] Is there a cross browser way of setting style.float in Javascript?

查看:65
本文介绍了有没有在Javascript中设置style.float的跨浏览器方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常,如果您需要在JavaScript中设置样式属性,请说:

Usually, if you need to set a style attribute in JavaScript, you say something like:

element.style.attribute = "value";

有一些细微的变化,但通常属性名称是类似的,尽管是camelcased,HTML属性的版本name。

There are slight variations but usually the attribute name is a similar, albeit camelcased, version of the HTML attribute name.

我的问题是float属性不起作用。 Float是JavaScript中的关键字,因此style.float会为分页符创建所有JavaScript。我查看了MSDN,它说像是这样使用styleFloat:

The problem for me is that the float attribute doesn't work. Float is a keyword in JavaScript and so style.float makes all the JavaScript for the page break. I looked in MSDN, and it said to use styleFloat like so:

element.style.styleFloat = "value";

仅适用于IE。 Firefox,Safari,Chrome,Opera - 它们似乎都没有答案。我哪里错了?必须有一个简单的答案。

That only works in IE. Firefox, Safari, Chrome, Opera - none of them seem to have an answer. Where am I going wrong? There has to be a simple answer to this.

推荐答案

在...中使用cssFloat

Use cssFloat as in...

element.style.cssFloat = "value";

除 IE 8及更早版本外,其他所有内容均可用,但您可以随时使用检测浏览器并切换,或者只设置它们。不幸的是,没有办法在所有浏览器中只设置一个样式值。

That works in everything except IE 8 and older, but you can always detect the browser and switch, or just set them both. Unfortuantely, there is no way to set just one style value to work in all browsers.

总而言之,你需要设置浮动的所有人,只需说:

So to summarize, everyone you need to set the float, just say:

element.style.styleFloat = "value";
element.style.cssFloat = "value";

在任何地方工作。

这篇关于有没有在Javascript中设置style.float的跨浏览器方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆