W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
有三種方法可以使用按鈕通過設(shè)置三個(gè)不同的type屬性。
當(dāng)您設(shè)置要submit
按鈕的type
屬性時(shí),按下按鈕將提交包含按鈕的表單。
這是未應(yīng)用 type
屬性時(shí)的默認(rèn)行為。
提交按鈕具有以下列出的一些附加屬性。
以下代碼顯示了如何將這些屬性應(yīng)用于按鈕元素。
<!DOCTYPE HTML> <html> <body> <form> <p> <label for="fave">Fruit: <input autofocus id="fave" name="fave" /></label> </p> <p> <label for="name">Name: <input id="name" name="name" /></label> </p> <button type="submit" formaction="http://example.com/form" formmethod="post">Submit Vote</button> </form> </body> </html>
上面的代碼從表單元素中省略了action和method屬性,并通過button元素上的 formaction
和 formmethod
屬性提供了配置。
如果將某個(gè)button
的type
屬性設(shè)置為reset
,則按下該按鈕可將表單中的所有輸入元素重置為其初始狀態(tài)。
重置按鈕沒有其他屬性。
以下代碼顯示了向HTML文檔添加重置按鈕。
<!DOCTYPE HTML>
<html>
<body>
<form method="post" action="http://example.com/form">
<p>
<label for="fave">Fruit:
<input autofocus id="fave" name="fave" /></label>
</p>
<p>
<label for="name">Name: <input id="name" name="name" /></label>
</p>
<button type="submit">Submit Vote</button>
<button type="reset">Reset</button>
</form>
</body>
</html>
如果將type
屬性設(shè)置為button
,則創(chuàng)建一個(gè)普通按鈕。它沒有特殊的意義,不會(huì)做任何事情,當(dāng)你按它。
以下代碼顯示了一個(gè)通用按鈕。
<!DOCTYPE HTML>
<html>
<body>
<form method="post" action="http://example.com/form">
<p>
<label for="fave">Fruit: <input autofocus id="fave"
name="fave" /></label>
</p>
<p>
<label for="name">Name: <input id="name" name="name" /></label>
</p>
<button type="button">
Do <strong>NOT</strong> press this button
</button>
</form>
</body>
</html>
您可以對按鈕元素中包含的文本設(shè)置樣式。
<html>
<body>
<form action="" method="post">
<button type="submit">Submit</button>
<br /><br />
<button type="reset"><b>Clear this form</b> I want to start again</button>
<br /><br />
<button type="button"><img src="http://www.m.o2fo.com/style/download.png" alt="submit" /></button>
</form>
</body>
</html>
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: