diff --git a/files/zh-cn/web/api/speechgrammar/weight/index.md b/files/zh-cn/web/api/speechgrammar/weight/index.md index 33adbb1652cce1..e2a2144fcbe615 100644 --- a/files/zh-cn/web/api/speechgrammar/weight/index.md +++ b/files/zh-cn/web/api/speechgrammar/weight/index.md @@ -1,34 +1,30 @@ --- -title: SpeechGrammar.weight +title: SpeechGrammar:weight 属性 slug: Web/API/SpeechGrammar/weight +l10n: + sourceCommit: 23e1a97d50050a3b3518a4b2f67ccf42e5fd75b7 --- {{APIRef("Web Speech API")}}{{SeeCompatTable}} -{{domxref("SpeechGrammar")}} 接口的可选属性 **`weight`** 设置并返回了一个 `SpeechGrammar` 对象的权重。 +{{domxref("SpeechGrammar")}} 接口的 **`weight`** 可选属性用于设置和返回 `SpeechGrammar` 对象的权重。 -## 语法 +## 值 -```plain -var myGrammarWeight = speechGrammarInstance.weight; -``` - -### 值 - -浮点数表示了当前文法的权重,范围在 0.0-1.0 之间。 +表示语法权重的浮点数,范围为 0.0 到 1.0。 -## 样例 +## 示例 ```js -var grammar = +const grammar = "#JSGF V1.0; grammar colors; public = aqua | azure | beige | bisque | black | blue | brown | chocolate | coral | crimson | cyan | fuchsia | ghostwhite | gold | goldenrod | gray | green | indigo | ivory | khaki | lavender | lime | linen | magenta | maroon | moccasin | navy | olive | orange | orchid | peru | pink | plum | purple | red | salmon | sienna | silver | snow | tan | teal | thistle | tomato | turquoise | violet | white | yellow ;"; -var recognition = new SpeechRecognition(); -var speechRecognitionList = new SpeechGrammarList(); +const recognition = new SpeechRecognition(); +const speechRecognitionList = new SpeechGrammarList(); speechRecognitionList.addFromString(grammar, 1); recognition.grammars = speechRecognitionList; -console.log(speechRecognitionList[0].src); // 应该返回和上面文法变量一样的内容 -console.log(speechRecognitionList[0].weight); // 应该返回 1 - 与上面第四行所设置的权重一致 +console.log(speechRecognitionList[0].src); // 返回值应与语法变量的内容相同 +console.log(speechRecognitionList[0].weight); // 应返回 1——与 addFromString 中设置的权重相同。 ``` ## 规范 @@ -39,6 +35,6 @@ console.log(speechRecognitionList[0].weight); // 应该返回 1 - 与上面第 {{Compat}} -## 相关链接 +## 参见 - [Web Speech API](/zh-CN/docs/Web/API/Web_Speech_API)