| 
									
										
										
										
											2018-10-10 18:03:03 -04:00
										 |  |  | --- | 
					
						
							|  |  |  | id: bad87fee1348bd9aedd08830 | 
					
						
							| 
									
										
										
										
											2020-12-16 00:37:30 -07:00
										 |  |  | title: 给表单添加提交按钮 | 
					
						
							| 
									
										
										
										
											2018-10-10 18:03:03 -04:00
										 |  |  | challengeType: 0 | 
					
						
							| 
									
										
										
										
											2019-12-26 20:05:59 +08:00
										 |  |  | videoUrl: 'https://scrimba.com/p/pVMPUv/cp2Nkhz' | 
					
						
							|  |  |  | forumTopicId: 16627 | 
					
						
							| 
									
										
										
										
											2021-01-13 03:31:00 +01:00
										 |  |  | dashedName: add-a-submit-button-to-a-form | 
					
						
							| 
									
										
										
										
											2018-10-10 18:03:03 -04:00
										 |  |  | --- | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-16 00:37:30 -07:00
										 |  |  | # --description--
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-20 18:58:05 -08:00
										 |  |  | 让我们来给表单添加一个 `submit`(提交)按钮。 点击提交按钮时,表单中的数据将会被发送到 `action` 属性指定的 URL 上。 | 
					
						
							| 
									
										
										
										
											2020-12-16 00:37:30 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-26 20:05:59 +08:00
										 |  |  | 例如: | 
					
						
							| 
									
										
										
										
											2018-10-10 18:03:03 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-21 10:58:20 -06:00
										 |  |  | ```html | 
					
						
							|  |  |  | <button type="submit">this button submits the form</button> | 
					
						
							|  |  |  | ``` | 
					
						
							| 
									
										
										
										
											2020-12-16 00:37:30 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | # --instructions--
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-06 04:42:36 +00:00
										 |  |  | 在 `form` 的底部创建一个按钮,按钮的类型为 `submit`,文本为 `Submit`。 | 
					
						
							| 
									
										
										
										
											2020-12-16 00:37:30 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | # --hints--
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-06 04:42:36 +00:00
										 |  |  | 你的 `form` 里面应该有一个 `button`。 | 
					
						
							| 
									
										
										
										
											2020-12-16 00:37:30 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | ```js | 
					
						
							|  |  |  | assert($('form').children('button').length > 0); | 
					
						
							|  |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-08 11:20:48 -08:00
										 |  |  | 按钮的 `type` 属性值应为 `submit`。 | 
					
						
							| 
									
										
										
										
											2020-12-16 00:37:30 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | ```js | 
					
						
							|  |  |  | assert($('button').attr('type') === 'submit'); | 
					
						
							| 
									
										
										
										
											2018-10-10 18:03:03 -04:00
										 |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-08 11:20:48 -08:00
										 |  |  | 提交按钮的文本应为 `Submit` 。 | 
					
						
							| 
									
										
										
										
											2020-12-16 00:37:30 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | ```js | 
					
						
							|  |  |  | assert( | 
					
						
							|  |  |  |   $('button') | 
					
						
							|  |  |  |     .text() | 
					
						
							|  |  |  |     .match(/^\s*submit\s*$/gi) | 
					
						
							|  |  |  | ); | 
					
						
							|  |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-08 11:20:48 -08:00
										 |  |  | `button` 元素应有结束标签。 | 
					
						
							| 
									
										
										
										
											2020-12-16 00:37:30 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | ```js | 
					
						
							|  |  |  | assert( | 
					
						
							|  |  |  |   code.match(/<\/button>/g) && | 
					
						
							|  |  |  |     code.match(/<button/g) && | 
					
						
							|  |  |  |     code.match(/<\/button>/g).length === code.match(/<button/g).length | 
					
						
							|  |  |  | ); | 
					
						
							| 
									
										
										
										
											2018-10-10 18:03:03 -04:00
										 |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-13 03:31:00 +01:00
										 |  |  | # --seed--
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ## --seed-contents--
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ```html | 
					
						
							|  |  |  | <h2>CatPhotoApp</h2> | 
					
						
							|  |  |  | <main> | 
					
						
							|  |  |  |   <p>Click here to view more <a href="#">cat photos</a>.</p> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-28 00:16:44 +09:00
										 |  |  |   <a href="#"><img src="https://www.bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back."></a> | 
					
						
							| 
									
										
										
										
											2021-01-13 03:31:00 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   <p>Things cats love:</p> | 
					
						
							|  |  |  |   <ul> | 
					
						
							|  |  |  |     <li>cat nip</li> | 
					
						
							|  |  |  |     <li>laser pointers</li> | 
					
						
							|  |  |  |     <li>lasagna</li> | 
					
						
							|  |  |  |   </ul> | 
					
						
							|  |  |  |   <p>Top 3 things cats hate:</p> | 
					
						
							|  |  |  |   <ol> | 
					
						
							|  |  |  |     <li>flea treatment</li> | 
					
						
							|  |  |  |     <li>thunder</li> | 
					
						
							|  |  |  |     <li>other cats</li> | 
					
						
							|  |  |  |   </ol> | 
					
						
							| 
									
										
										
										
											2021-04-28 00:16:44 +09:00
										 |  |  |   <form action="https://www.freecatphotoapp.com/submit-cat-photo"> | 
					
						
							| 
									
										
										
										
											2021-01-13 03:31:00 +01:00
										 |  |  |     <input type="text" placeholder="cat photo URL"> | 
					
						
							|  |  |  |   </form> | 
					
						
							|  |  |  | </main> | 
					
						
							|  |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-16 00:37:30 -07:00
										 |  |  | # --solutions--
 | 
					
						
							| 
									
										
										
										
											2018-10-10 18:03:03 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-13 03:31:00 +01:00
										 |  |  | ```html | 
					
						
							|  |  |  | <h2>CatPhotoApp</h2> | 
					
						
							|  |  |  | <main> | 
					
						
							|  |  |  |   <p>Click here to view more <a href="#">cat photos</a>.</p> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-28 00:16:44 +09:00
										 |  |  |   <a href="#"><img src="https://www.bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back."></a> | 
					
						
							| 
									
										
										
										
											2021-01-13 03:31:00 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   <p>Things cats love:</p> | 
					
						
							|  |  |  |   <ul> | 
					
						
							|  |  |  |     <li>cat nip</li> | 
					
						
							|  |  |  |     <li>laser pointers</li> | 
					
						
							|  |  |  |     <li>lasagna</li> | 
					
						
							|  |  |  |   </ul> | 
					
						
							|  |  |  |   <p>Top 3 things cats hate:</p> | 
					
						
							|  |  |  |   <ol> | 
					
						
							|  |  |  |     <li>flea treatment</li> | 
					
						
							|  |  |  |     <li>thunder</li> | 
					
						
							|  |  |  |     <li>other cats</li> | 
					
						
							|  |  |  |   </ol> | 
					
						
							| 
									
										
										
										
											2021-04-28 00:16:44 +09:00
										 |  |  |   <form action="https://www.freecatphotoapp.com/submit-cat-photo"> | 
					
						
							| 
									
										
										
										
											2021-01-13 03:31:00 +01:00
										 |  |  |     <input type="text" placeholder="cat photo URL"> | 
					
						
							|  |  |  |     <button type="submit">Submit</button> | 
					
						
							|  |  |  |   </form> | 
					
						
							|  |  |  | </main> | 
					
						
							|  |  |  | ``` |