
批改狀態(tài):合格
老師批語:你的總結(jié)就是知識的羅列, 沒有多大意義 , 沒有個(gè)人主觀意見, 下次注意
1、代碼練習(xí)和演示
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>表單相關(guān)</title>
<style>
form {
width: 400px;
/* height: 400px; */
padding: 20px;
margin: auto;
background-color: #0ad4b9;
display: grid;
grid-gap: 15px;
}
form:hover {
box-shadow: 0 0 3px #616161;
}
h2 {
width: 400px;
margin: auto;
text-align: center;
}
section {
display: grid;
grid-template-columns: 80px 1fr;
}
section:last-child {
display: grid;
grid-template-columns: 1fr 1fr;
}
button {
height: 30px;
width: 60px;
border: none;
outline: none;
background-color: lightblue;
margin: auto;
}
button:hover {
background-color: red;
color: white;
}
fieldset > .other {
display: grid;
grid-template-columns: 80px repeat(6, 1fr);
}
legend {
text-align: center;
}
textarea {
width: 300px;
}
</style>
</head>
<body>
<h2>用戶登陸</h2>
<form action="login.php" method="POST">
<section>
<label for="username">用戶名:</label>
<input
type="text"
id="username"
name="username"
placeholder="用戶名"
required
autofocus
/>
</section>
<section>
<label for="pwd">密 碼:</label>
<input
type="password"
id="pwd"
name="password"
placeholder="不少于6位密碼"
required
/>
</section>
<section>
<button type="submit">登陸</button>
<button type="reset">重置</button>
</section>
</form>
<hr />
<h2>用戶注冊</h2>
<form action="" enctype="multipart/form-data">
<fieldset>
<legend>基本信息</legend>
<section>
<label for="username">用戶名:</label>
<input
type="text"
id="username"
name="username"
placeholder="用戶名"
required
/>
</section>
<section>
<label for="pwd">密 碼:</label>
<input
type="password"
id="pwd"
name="password"
placeholder="不少于6位密碼"
required
/>
</section>
<section class="other">
<label for="">性別:</label>
<input type="radio" name="sex" value="1" />男
<input type="radio" name="sex" value="0" checked />女
<input type="radio" name="sex" value="2" />保密
</section>
</fieldset>
<fieldset>
<legend>德智體美</legend>
<section class="other">
<label for="">愛好:</label>
<input type="checkbox" name="like[]" value="" checked />跑步
<input type="checkbox" name="like[]" value="" checked />游泳
<input type="checkbox" name="like[]" value="" />玩游戲
</section>
<section>
<label for="">特長</label>
<input type="text" list="course" name="course" />
<datalist id="course">
<option value="html">html</option>
<option value="css">css</option>
<option value="javascript">javascript</option>
</datalist>
</section>
<section>
<label for="php">科目</label>
<select name="php" id="php">
<optgroup label="前端">
<option value="html">html</option>
<option value="css">css</option>
<option value="javascript">javascript</option>
</optgroup>
<optgroup label="后端">
<option value="php" label="php"></option>
<option value="composer" label="composer" selected></option>
<option value="laravel">laravel</option>
</optgroup>
</select>
</section>
<section>
<label for="">頭像:</label>
<input type="hidden" name="MAX_FILE_SIZE" value="800000" />
<input type="file" name="" id="" />
</section>
<section>
<label for="">圖片域:</label>
<input type="image" src="dy.png" width="80px" height="30px" />
</section>
<section>
<h4>個(gè)人介紹</h4>
<textarea
name=""
id=""
cols=""
rows="10"
placeholder="自我介紹……"
></textarea>
</section>
</fieldset>
<section>
<button
type="submit"
formaction="login"
formmethod="POSt"
formtarget="_blank"
>
登陸
</button>
<button type="submit" formaction="">發(fā)送</button>
</section>
</form>
</body>
</html>
2、代碼運(yùn)行結(jié)果圖
1、相關(guān)知識總結(jié)
1、表單相關(guān)常見標(biāo)簽:
表單:<form></form>
、
控件:<label></label>
和<input/>
、
按鈕:<botton></botton>
、
自定義列表:<select><optgroup label="分組"><option>自定義列表項(xiàng)<option/><optgroup></select>
、
預(yù)定義輸入:<input list="course"/>
和<datalist id="course"> <option>預(yù)定義選項(xiàng)</option></datalist>
分組標(biāo)簽:<fieldset></fieldset>
和<legend></legend>
2、表單相關(guān)屬性:
a、form: action=”請求處理地址”,method=”請求發(fā)送方式(GET|POST)”,target=”打開方式(_blank)” ,name=”表單名稱”,enctype=”application/x-www-form-urlencoded | multipart/form-data”
b、input: type=”控件類型見c項(xiàng)”、name=”空間名字”,value=”控件值”,form=”空間所屬表單”,placeholder=”提示信息占位符(text和password)”, autofocus:自動(dòng)獲取焦點(diǎn),checked:默認(rèn)選項(xiàng)(radio和checkbox)等等
c、input空間類型:text password radio checkbox file image hidden email data和datatime-local tel url number range(范圍拖動(dòng)條) search color等
d、button type=”submit|reset|button”,name=”名字”,value=”按鈕文本值”,form相關(guān)屬性:formaction和form……
e、select : name=”請求參數(shù)名稱”,multiple:是否多選(布爾值) size=”允許顯示的列表數(shù)量”
3、表單相關(guān)事件:
序號 | 事件屬性 | 描述 |
---|---|---|
1 | onfocus |
獲取焦點(diǎn)時(shí)觸發(fā) |
2 | onblur |
失去焦點(diǎn)時(shí)觸發(fā) |
3 | onchange |
失去焦點(diǎn),且值發(fā)生變化時(shí)觸發(fā) |
4 | oninput |
值發(fā)生變化(不等失去焦點(diǎn))時(shí)觸發(fā) |
5 | onkeydown |
按下鍵盤時(shí)觸發(fā) |
6 | onkeyup |
抬起鍵盤時(shí)觸發(fā) |
7 | onclick |
鼠標(biāo)單擊時(shí)觸發(fā) |
8 | onselect |
選擇內(nèi)容文本時(shí)觸發(fā) |
微信掃碼
關(guān)注PHP中文網(wǎng)服務(wù)號
QQ掃碼
加入技術(shù)交流群
Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號