安全上下文
此特征只可用于 安全上下文 (HTTPS),在某些或所有 支持浏览器 .

只读 length property returns an integer value indicating the number of items in the input source list represented by the XRInputSourceArray 对象。

句法

let inputSourceCount = xrInputSourceArray.length;
					

An integer value indicating the number of XRInputSource objects representing WebXR input sources are includled in the array.

范例

In this example, a game that requires at least one input source uses length to check this before proceeding to allow the user to play the game.

let sources = xrSession.inputSources;
if (sources.length === 0) {
  showAlertDialog("You need to have at least one controller to play Super Duper Shark Jump Fest 9000.",
                  [
                    { label: "Shop Now", url: "https://www.amazon.com/s?k=vr+controllers" },
                    { label: "Quit" handler: quitGame }
                  ]);
}
					

Here, if length is 0, a hypothetical showAlertDialog() function is called with a prompt string explaining the need for a controller, and an array of objects, each describing a button and what should happen when it's clicked. The first takes the user to an Amazon.com search for VR controllers, and the second calls a quitGame() function to start shutting the game program down.

规范

规范 状态 注释
WebXR 设备 API
The definition of 'XRInputSourceArray.length' in that specification.
工作草案 初始定义。

浏览器兼容性

更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
length Chrome 79 Edge 79 Firefox No IE No Opera No Safari No WebView Android No Chrome Android 79 Firefox Android No Opera Android No Safari iOS No Samsung Internet Android 11.2

图例

完整支持

完整支持

不支持

不支持

元数据

  • 最后修改: