--- id: bad87fee1348bd9aedf08835 title: 創建一組複選框 challengeType: 0 videoUrl: 'https://scrimba.com/p/pVMPUv/cqrkJsp' forumTopicId: 16821 dashedName: create-a-set-of-checkboxes --- # --description-- checkboxes(複選框)就好比多項選擇題,正確答案有多個。 複選框是 `input` 選擇框的一種類型。 每一個複選框都應該嵌套在它自己的 `label`(標籤)元素中。 這樣,我們相當於給 `input` 元素和包裹它的 `label` 元素建立起了對應關係。 所有關聯的複選框應該擁有相同的 `name` 屬性。 使得 `input` 與 `label` 關聯的最佳實踐是在 `label` 元素上設置 `for` 屬性,讓其值與相關聯的 `input` 複選框的 `id` 屬性值相同。 下面是一個複選框的例子: ```html Loving ``` # --instructions-- 請給表單添加三個複選框, 每個複選框都被嵌套進 `label` 元素中。 並且它們的 `name` 屬性均爲 `personality`。 # --hints-- 表單中應存在三個複選框。 ```js assert($('input[type="checkbox"]').length > 2); ``` 每個複選框都應該被嵌套進 `label` 元素中。 ```js assert($('label > input[type="checkbox"]:only-child').length > 2); ``` 確保 `label` 元素有結束標籤。 ```js assert( code.match(/<\/label>/g) && code.match(//g).length === code.match(/ input[type="checkbox"]').filter('[name="personality"]').length > 2 ); ``` 每個複選框都應該在 `form` 標籤內。 ```js assert($('label').parent().get(0).tagName.match('FORM')); ``` # --seed-- ## --seed-contents-- ```html CatPhotoApp Click here to view more cat photos. Things cats love: cat nip laser pointers lasagna Top 3 things cats hate: flea treatment thunder other cats Indoor Outdoor Submit ``` # --solutions-- ```html CatPhotoApp Click here to view more cat photos. Things cats love: cat nip laser pointers lasagna Top 3 things cats hate: flea treatment thunder other cats Indoor Outdoor Playful Lazy Evil Submit ```
Click here to view more cat photos.
Things cats love:
Top 3 things cats hate: