允許作答者選取一或多個核取方塊,以及選填的「其他」欄位。您可以透過 Form 存取或建立項目。在測驗中使用時,系統會自動評分這些項目。
// Open a form by ID and add a new checkbox item. const form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz'); const item = form.addCheckboxItem(); item.setTitle('What condiments would you like on your hot dog?') .setChoices([ item.createChoice('Ketchup'), item.createChoice('Mustard'), item.createChoice('Relish'), ]) .showOtherOption(true);
方法
內容詳盡的說明文件
clear Validation()
移除這個核取方塊項目的所有資料驗證。
回攻員
Checkbox — 這個 Checkbox,用於鏈結
授權
使用這個方法的腳本需要具備下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly -
https://www.googleapis.com/auth/forms
create Choice(value)
create Choice(value, isCorrect)
create Response(responses)
為此核取方塊項目建立新的 Item。引數 responses 是 String[] 陣列,其中包含需要檢查的值。如果任何值不符合此項目的有效選項,系統就會擲回例外狀況 (除非 show 設為 true)。
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
responses | String[] | 這個選擇題項目的有效答案陣列 |
回攻員
Item:項目回應
授權
使用這個方法的腳本需要具備下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly -
https://www.googleapis.com/auth/forms
duplicate()
建立此項目的副本,並附加至表單結尾。
回攻員
Checkbox:這個 Checkbox 的複本,用於鏈結
授權
使用這個方法的腳本需要具備下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly -
https://www.googleapis.com/auth/forms
get Choices()
get Feedback For Correct()
在作答者正確回答問題時,傳回要向他們顯示的意見回饋。
回攻員
Quiz - 意見回饋 (如果有的話)。
授權
使用這個方法的腳本需要具備下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly -
https://www.googleapis.com/auth/forms
get Feedback For Incorrect()
當作答者回答問題時,系統會傳回這項回饋。
回攻員
Quiz - 意見回饋 (如果有的話)。
授權
使用這個方法的腳本需要具備下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly -
https://www.googleapis.com/auth/forms
get Help Text()
取得項目的說明文字 (有時稱為版面配置項目的說明文字,例如 Image、Page 和 Section)。
回攻員
String:項目的說明文字或說明文字
授權
使用這個方法的腳本需要具備下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly -
https://www.googleapis.com/auth/forms
get Id()
取得項目的專屬 ID。
回攻員
Integer:商品 ID
授權
使用這個方法的腳本需要具備下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly -
https://www.googleapis.com/auth/forms
get Index()
取得表單中所有項目中的項目索引。
回攻員
Integer:項目索引
授權
使用這個方法的腳本需要具備下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly -
https://www.googleapis.com/auth/forms
get Points()
傳回可評分的項目分數。
回攻員
Integer:問題的分數。
授權
使用這個方法的腳本需要具備下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly -
https://www.googleapis.com/auth/forms
get Title()
取得項目的標題 (在 Section 的情況下,有時稱為標頭文字)。
回攻員
String:項目的標題或標頭文字
授權
使用這個方法的腳本需要具備下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly -
https://www.googleapis.com/auth/forms
get Type()
has Other Option()
判斷項目是否有「其他」選項。
回攻員
Boolean:如果項目有「其他」選項,則為 true;如果沒有,則為 false
授權
使用這個方法的腳本需要具備下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly -
https://www.googleapis.com/auth/forms
is Required()
決定受訪者是否必須回答問題。
回攻員
Boolean:受訪者是否必須回答問題
授權
使用這個方法的腳本需要具備下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly -
https://www.googleapis.com/auth/forms
set Choice Values(values)
從字串陣列中設定項目的選項。如果指定的陣列為空白,就會擲回例外狀況。
// Open a form by ID and add a new list item. const form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz'); const item = form.addListItem(); item.setTitle('Do you prefer cats or dogs?'); item.setChoiceValues(['Dogs', 'Cats']);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
values | String[] | 選項值陣列,作答者在查看表單時會看到這些標籤 |
回攻員
Checkbox — 這個 Checkbox,用於鏈結
授權
使用這個方法的腳本需要具備下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly -
https://www.googleapis.com/auth/forms
set Choices(choices)
為項目設定陣列選項。如果指定的陣列為空白或包含 null 元素,就會擲回例外狀況。
// Open a form by ID and add a new list item. const form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz'); const item = form.addListItem(); item.setTitle('Do you prefer cats or dogs?'); item.setChoices([item.createChoice('Cats'), item.createChoice('Dogs')]);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
choices | Choice[] | 選擇項目陣列 |
回攻員
Checkbox — 這個 Checkbox,用於鏈結
擲回
Error:如果指定的陣列為 null、空白或包含 null 元素
授權
使用這個方法的腳本需要具備下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly -
https://www.googleapis.com/auth/forms
set Feedback For Correct(feedback)
設定在作答者正確回答問題時,向他們顯示的意見回饋。
// Open a form by ID and add a new list item. const form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz'); const item = form.addListItem(); item.setTitle('Do you prefer cats or dogs?'); // Set "Dogs" as the correct answer to this question. item.setChoices([ item.createChoice('Dogs', true), item.createChoice('Cats', false), ]); // Add feedback which will be shown for correct responses; ie "Dogs". item.setFeedbackForCorrect( FormApp.createFeedback().setDisplayText('Dogs rule, cats drool.').build(), );
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
feedback | Quiz | 新的意見回饋。空值會清除意見回饋。 |
回攻員
Checkbox — 這個 Checkbox,用於鏈結
授權
使用這個方法的腳本需要具備下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly -
https://www.googleapis.com/auth/forms
set Feedback For Incorrect(feedback)
設定作答者回答問題時,系統向他們顯示的意見回饋。
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
feedback | Quiz | 新的意見回饋 |
回攻員
Checkbox — 這個 Checkbox,用於鏈結
授權
使用這個方法的腳本需要具備下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly -
https://www.googleapis.com/auth/forms
set Help Text(text)
設定項目的說明文字 (對於 Image、Page 和 Section 等版面配置項目,有時稱為說明文字)。
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
text | String | 新的說明文字 |
回攻員
Checkbox — 這個 Checkbox,用於鏈結
授權
使用這個方法的腳本需要具備下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly -
https://www.googleapis.com/auth/forms
set Points(points)
設定可評分的項目可獲得的分數。新項目的預設值為 0。
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
points | Integer | 問題項目的分數 |
回攻員
Checkbox — 這個 Checkbox,用於鏈結
授權
使用這個方法的腳本需要具備下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly -
https://www.googleapis.com/auth/forms
set Required(enabled)
設定受訪者是否必須回答問題。
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
enabled | Boolean | 是否要求受訪者回答問題 |
回攻員
Checkbox:目前的項目 (用於鏈結)
授權
使用這個方法的腳本需要具備下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly -
https://www.googleapis.com/auth/forms
set Title(title)
設定項目的標題 (在 Section 的情況下,有時稱為標頭文字)。
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
title | String | 新的標題或標頭文字 |
回攻員
Checkbox — 這個 Checkbox,用於鏈結
授權
使用這個方法的腳本需要具備下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly -
https://www.googleapis.com/auth/forms
set Validation(validation)
設定此核取方塊項目的資料驗證。傳入空值或未呼叫任何 require 函式的驗證,會移除先前的驗證。
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
validation | Checkbox | 要套用至此項目的 CheckboxValidation。 |
回攻員
Checkbox — 這個 Checkbox,用於鏈結
授權
使用這個方法的腳本需要具備下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly -
https://www.googleapis.com/auth/forms
show Other Option(enabled)
設定項目是否有「其他」選項。新 Checkbox 或 Multiple 的預設值為 false。
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
enabled | Boolean | true 如果項目有「其他」選項;false如果沒有 |
回攻員
Checkbox — 這個 Checkbox,用於鏈結
授權
使用這個方法的腳本需要具備下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly -
https://www.googleapis.com/auth/forms