js獲取選中radio單選按鈕的值程式碼例項
本章節分享一段程式碼例項,它實現了獲取選中radio單選按鈕值得功能。
程式碼例項如下:
[HTML] 純文字檢視 複製程式碼<!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta name="author" content="http://www.softwhy.com/" /> <title>螞蟻部落</title> <script> function getRadioBoxValue(radioName) { var obj = document.getElementsByName(radioName); for (var index = 0; index < obj.length; index ++) { if (obj[index].checked) { return obj[index ].value; } } return "undefined"; } window.onload = function () { var odiv = document.getElementById("show"); odiv.innerHTML = getRadioBoxValue("antzone"); } </script> </head> <body> <div id="box"> <form> <input type="radio" name="antzone" value="螞蟻部落一"/> <input type="radio" checked name="antzone" value="螞蟻部落二" /> <input type="radio" name="antzone" value="螞蟻部落三" /> </form> </div> <div id="show"></div> </body> </html>
上面的程式碼實現了我們的要求,程式碼非常的簡單,更多內容可以參閱相關閱讀。
相關閱讀:
(1).document.getElementsByName()可以參閱document.getElementsByName()一章節。
(2).innerHTML屬性可以參閱innerHTML一章節。
相關文章
- js如何獲取選中radio單選按鈕的值JS
- JavaScript獲取選中radio單選按鈕值JavaScript
- JavaScript 獲取radio 選中單選按鈕值JavaScript
- jQuery獲取被選中radio單選按鈕的值jQuery
- jQuery如何獲取選中單選按鈕radio的值jQuery
- 原生js獲取radio按鈕選中值程式碼JS
- js如何取得選中的單選按鈕radio的值JS
- 獲取選中表單按鈕的值
- js單選按鈕radio選中值JS
- js遍歷raido單選按鈕並獲取選中值程式碼JSAI
- js獲取選中文字值的例項程式碼JS
- radio 單選按鈕 選中多個
- jQuery獲取選中的核取方塊或者單按鈕的值jQuery
- js表單提交後提交按鈕不可點選程式碼例項JS
- jQuery獲取選中核取方塊的值程式碼例項jQuery
- js獲取點選單元格中的內容程式碼例項JS
- js獲取鍵盤按鍵值程式碼例項JS
- 設定radio單選按鈕預設選中
- 獲取選中checkbox核取方塊的值程式碼例項
- js獲取當前select下拉選單選中項的值JS
- css自定義單選按鈕的樣式程式碼例項CSS
- js獲取選中文字程式碼例項JS
- js點選按鈕數字加1效果程式碼例項JS
- HTML input radio 單選按鈕HTML
- HTML input radio單選按鈕HTML
- radio單選按鈕美化效果
- 點選按鈕複製連結程式碼例項
- javascript動態改變單選按鈕radio的選中狀態JavaScript
- js如何獲取css偽類選擇器樣式值程式碼例項JSCSS
- html如何設定radio單選按鈕預設選中效果HTML
- jQuery判斷一個radio單選按鈕是否被選中jQuery
- js取得gridview中獲取checkbox選中的值--單選JSView
- js實現的獲取選中文字程式碼例項JS
- 防止表單提交按鈕重複點選現象程式碼例項
- 單選按鈕美化效果程式碼
- javascript 點選回車相當於點選按鈕程式碼例項JavaScript
- 點選按鈕複製文字框文字程式碼例項
- CSS3 美化radio單選按鈕CSSS3