我們先來看input標簽的格式
input id= (id) name= (組名稱) type= radio /input
注:對于需要選中檢索的值,可以利用表單的提交或使用JavaScript獲取。
我們來看具體的示例
代碼如下
!DOCTYPE html html head meta http-equiv= Content-Type content= text/html; charset=utf-8 / title /title /head body form name= form1 action= input id= Radio1 name= RadioGroup1 type= radio / label for= Radio1 單選按鈕 元素1 /label br/ input id= Radio2 name= RadioGroup1 type= radio / label for= Radio2 單選按鈕 元素2 /label br / input id= Radio3 name= RadioGroup1 type= radio / label for= Radio3 單選按鈕 元素3 /label br / /form div id= output /div /body /html
運行結果
使用Web瀏覽器打開上述HTML文件時,將顯示如下所示的效果。
單擊以更改單選按鈕的選中狀態
在多個組中使用RadioButton時
代碼如下
!DOCTYPE html html head meta http-equiv= Content-Type content= text/html; charset=utf-8 / title /title /head body form name= form1 action= div >說明:
要將單選按鈕分成多個組,請將每個組的name屬性設置為不同名稱。在上面的例子中,Radio 1,Radio 2,Radio 3的name屬性是group 1。Radio 4,Radio 5,Radio 6的name屬性是第2組。
運行結果
使用Web瀏覽器打開上述HTML文件時,將顯示如下所示的效果。
每組都是分開的,單選按鈕的選擇是獨立的。
以上就是HTML如何實現RadioButton單選按鈕的詳細內容,html教程
鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。
新聞熱點
疑難解答