--- id: bad87fee1348bd9aedd08835 title: 给单选按钮和复选框添加默认选中项 challengeType: 0 videoUrl: 'https://scrimba.com/p/pVMPUv/cWk3Qh6' forumTopicId: 301094 dashedName: check-radio-buttons-and-checkboxes-by-default --- # --description-- 用 `checked` 属性把第一个复选框和单选按钮都设置为默认选中。 在一个 input 元素里面添加 `checked` 这个词,即可实现。 例如: ```html ``` # --instructions-- 把第一个单选按钮和第一个复选框都设置为默认选中。 # --hints-- 表单的第一个多选按钮应被默认选中。 ```js assert($('input[type="radio"]').prop('checked')); ``` 表单的第一个复选框应被默认选中。 ```js assert($('input[type="checkbox"]').prop('checked')); ``` # --seed-- ## --seed-contents-- ```html

CatPhotoApp

Click here to view more cat photos.

A cute orange cat lying on its back.

Things cats love:

Top 3 things cats hate:

  1. flea treatment
  2. thunder
  3. other cats


``` # --solutions-- ```html

CatPhotoApp

Click here to view more cat photos.

A cute orange cat lying on its back.

Things cats love:

Top 3 things cats hate:

  1. flea treatment
  2. thunder
  3. other cats


```