setFloatValue() 方法在 CSSPrimitiveValue interface is used to set a float value. If the property attached to this value can't accept the specified unit or the float value, the value will be unchanged and a DOMException 会被引发。

句法

cssPrimitiveValue.setFloatValue(unitType, floatValue);
					

参数

unitType
An unsigned short representing the code for the unit type, in which the value should be returned. Valid values are:
常量 描述
CSS_CM The value is a <length> in centimeters.
CSS_DEG The value is an <angle> in degrees.
CSS_DIMENSION The value is a <number> with an unknown dimension.
CSS_EMS The value is a <length> in em units.
CSS_EXS The value is a <length> in ex units.
CSS_GRAD The value is an <angle> in grads.
CSS_HZ The value is a <frequency> in Hertz. The value can be obtained by using the getFloatValue method.
CSS_IN The value is a <length> in inches.
CSS_KHZ The value is a <frequency> in Kilohertz.
CSS_MM The value is a <length> in millimeters.
CSS_MS The value is a <time> in milliseconds.
CSS_NUMBER The value is a simple <number> .
CSS_PC The value is a <length> in picas.
CSS_PERCENTAGE The value is a <percentage> .
CSS_PT The value is a <length> in points.
CSS_PX The value is a <length> (以像素为单位)。
CSS_RAD The value is an <angle> in radians.
CSS_S The value is a <time> in seconds.
floatValue
A float representing the new float value.

返回值

Void.

异常

类型 描述
DOMException An INVALID_ACCESS_ERR is raised if the CSS value doesn't contain a float value or if the string value can't be converted into the specified unit.
An NO_MODIFICATION_ALLOWED_ERR is raised if this property is read-only.

规范

规范 状态 注释
Document Object Model (DOM) Level 2 Style Specification
The definition of 'CSSPrimitiveValue.setFloatValue' in that specification.
过时 初始定义

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
setFloatValue 弃用 Chrome 不支持 No Edge 不支持 No Firefox 不支持 ? — 62 IE ? Opera 不支持 No Safari ? WebView Android 不支持 No Chrome Android 不支持 No Firefox Android 不支持 4 — 62 Opera Android ? Safari iOS ? Samsung Internet Android 不支持 No

图例

不支持

不支持

兼容性未知 ?

兼容性未知

弃用。不要用于新网站。

弃用。不要用于新网站。

元数据

  • 最后修改: