讓作答者選取一或多個核取方塊,以及選用的「其他」欄位的問題。您可以透過 Form
存取或建立項目。在測驗中時,這些項目會自動評分。
// Open a form by ID and add a new checkbox item. var form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz'); var 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);
方法
內容詳盡的說明文件
clearValidation()
移除這個核取方塊項目的任何資料驗證。
Return 鍵
CheckboxItem
— 這個 CheckboxItem
用於鏈結
授權
如果指令碼使用這個方法,就必須符合下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
createChoice(value)
createChoice(value, isCorrect)
createResponse(responses)
為這個核取方塊項目建立新的 ItemResponse
。引數 responses
是包含需要檢查值的 String[]
陣列。除非 showOtherOption(enabled)
設為 true
,否則如有任何值不符合此項目的有效選項,則擲回例外狀況。
參數
名稱 | 類型 | 說明 |
---|---|---|
responses | String[] | 這個選擇題的有效答案陣列 |
Return 鍵
ItemResponse
:項目回應
授權
如果指令碼使用這個方法,就必須符合下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
duplicate()
建立這個項目的副本,然後附加到表單結尾。
Return 鍵
CheckboxItem
:與這個 CheckboxItem
重複,用於鏈結
授權
如果指令碼使用這個方法,就必須符合下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
getChoices()
getFeedbackForCorrect()
傳回作答者在正確回答問題時看到的意見回饋。
Return 鍵
QuizFeedback
:意見回饋 (如果有的話)。
授權
如果指令碼使用這個方法,就必須符合下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
getFeedbackForIncorrect()
傳回作答者在未正確回答問題時提供的意見回饋。
Return 鍵
QuizFeedback
:意見回饋 (如果有的話)。
授權
如果指令碼使用這個方法,就必須符合下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
getHelpText()
取得商品的說明文字 (有時為版面配置項目的說明文字,例如 ImageItems
、PageBreakItems
和 SectionHeaderItems
)。
Return 鍵
String
:項目的說明文字或說明文字
授權
如果指令碼使用這個方法,就必須符合下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
getId()
取得商品的專屬 ID。
Return 鍵
Integer
:該項目的 ID
授權
如果指令碼使用這個方法,就必須符合下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
getIndex()
取得表單中所有商品的索引。
Return 鍵
Integer
:項目的索引
授權
如果指令碼使用這個方法,就必須符合下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
getPoints()
傳回可評分項目的分數值。
Return 鍵
Integer
:每個問題的相關價值。
授權
如果指令碼使用這個方法,就必須符合下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
getTitle()
取得商品標題 (有時為 SectionHeaderItem
標頭)。
Return 鍵
String
:項目的標題或標題文字
授權
如果指令碼使用這個方法,就必須符合下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
getType()
hasOtherOption()
判斷該項目是否設有「other」選項。
Return 鍵
Boolean
— 如果該項目有「other」選項,則為 true
;如果不是,則設為 false
授權
如果指令碼使用這個方法,就必須符合下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
isRequired()
判斷作答者是否需要回答問題。
Return 鍵
Boolean
— 作答者必須回答問題
授權
如果指令碼使用這個方法,就必須符合下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
setChoiceValues(values)
從字串陣列設定項目的選項。如果指定的陣列為空白,則擲回例外狀況。
// Open a form by ID and add a new list item. var form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz'); var item = form.addListItem(); item.setTitle('Do you prefer cats or dogs?'); item.setChoiceValues(['Dogs', 'Cats']);
參數
名稱 | 類型 | 說明 |
---|---|---|
values | String[] | 自選值陣列,作答者會在查看表單時將其顯示為標籤 |
Return 鍵
CheckboxItem
— 這個 CheckboxItem
用於鏈結
授權
如果指令碼使用這個方法,就必須符合下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
setChoices(choices)
設定項目的選項陣列。如果指定陣列為空白或包含 null
元素,則擲回例外狀況。
// Open a form by ID and add a new list item. var form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz'); var item = form.addListItem(); item.setTitle('Do you prefer cats or dogs?') item.setChoices([ item.createChoice('Cats'), item.createChoice('Dogs') ]);
參數
名稱 | 類型 | 說明 |
---|---|---|
choices | Choice[] | 一系列選項 |
Return 鍵
CheckboxItem
— 這個 CheckboxItem
用於鏈結
擲回
Error
— 如果指定的陣列是 null
、空白或包含 null
元素
授權
如果指令碼使用這個方法,就必須符合下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
setFeedbackForCorrect(feedback)
設定當問題正確回應時,向作答者顯示意見回饋。
// Open a form by ID and add a new list item. var form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz'); var 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 | QuizFeedback | 新的意見回饋。空值會清除意見回饋。 |
Return 鍵
CheckboxItem
— 這個 CheckboxItem
用於鏈結
授權
如果指令碼使用這個方法,就必須符合下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
setFeedbackForIncorrect(feedback)
設定當作答者未正確回答問題時,是否要顯示意見回饋。
參數
名稱 | 類型 | 說明 |
---|---|---|
feedback | QuizFeedback | 新的意見回饋 |
Return 鍵
CheckboxItem
— 這個 CheckboxItem
用於鏈結
授權
如果指令碼使用這個方法,就必須符合下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
setHelpText(text)
設定項目的說明文字 (有時是指 ImageItems
、PageBreakItems
和 SectionHeaderItems
等版面配置項目的說明文字)。
參數
名稱 | 類型 | 說明 |
---|---|---|
text | String | 新的說明文字 |
Return 鍵
CheckboxItem
— 這個 CheckboxItem
用於鏈結
授權
如果指令碼使用這個方法,就必須符合下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
setPoints(points)
設定可評分項目的數值。新項目的預設值為 0。
參數
名稱 | 類型 | 說明 |
---|---|---|
points | Integer | 問題項目的分數 |
Return 鍵
CheckboxItem
— 這個 CheckboxItem
用於鏈結
授權
如果指令碼使用這個方法,就必須符合下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
setRequired(enabled)
設定作答者是否需要回答問題。
參數
名稱 | 類型 | 說明 |
---|---|---|
enabled | Boolean | 作答者是否需要回答問題 |
Return 鍵
CheckboxItem
:目前的項目 (用於鏈結)
授權
如果指令碼使用這個方法,就必須符合下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
setTitle(title)
設定項目標題 (有時在 SectionHeaderItem
中稱為標題文字)。
參數
名稱 | 類型 | 說明 |
---|---|---|
title | String | 新的標題或標題文字 |
Return 鍵
CheckboxItem
— 這個 CheckboxItem
用於鏈結
授權
如果指令碼使用這個方法,就必須符合下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
setValidation(validation)
設定這個核取方塊項目的資料驗證。如果傳入空值或驗證,不需要使用任何呼叫函式即可移除任何先前的驗證。
參數
名稱 | 類型 | 說明 |
---|---|---|
validation | CheckboxValidation | 要套用至這個項目的 核取方塊方塊。 |
Return 鍵
CheckboxItem
— 這個 CheckboxItem
用於鏈結
授權
如果指令碼使用這個方法,就必須符合下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
showOtherOption(enabled)
設定該項目是否提供「other」選項。新的 CheckboxItem
或 MultipleChoiceItem
的預設值為 false
。
參數
名稱 | 類型 | 說明 |
---|---|---|
enabled | Boolean | 如果商品有「other」選項,則為 true ;如果否,則為 false |
Return 鍵
CheckboxItem
— 這個 CheckboxItem
用於鏈結
授權
如果指令碼使用這個方法,就必須符合下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms