我想根據用戶選擇顯示單選按鈕值,但警報時我沒有獲取值。 我也想作爲圖像來顯示單選按鈕的值..像當用戶選擇男男然後PIC顯示檢索圖像中選定的單選按鈕值
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<form id="test">
<h4>Gender</h4>
<input type="radio" name="gender" value="male"> Male<br>
<input type="radio" name="gender" value="female"> Female<br>
<h4>Occupation</h4>
<input type="radio" name="occupation" value="PvtJob">Pvt. Job<br>
<input type="radio" name="occupation" value="Govt">Govt. Employee<br>
<h4>Loan Type</h4>
<input type="radio" name="loan" value="Personal">Personal Loan<br>
<input type="radio" name="loan" value="Health">Health Loan<br><br>
<button class="btn btn-primary pull-right place-order-button" name="submit" value="submit" onclick="return myFunction()" type="submit" >Finish</button>
</form>
</body>
<script type="text/javascript">
function myFunction() {
var radioButtons =["gender","occupation","loan"];
for(var x = 0; x < radioButtons.length; x ++) {
if ($('input[name = "'+radioButtons[x]+'"]:checked','#test').val()) {
alert("You checked " + $('input[name = "'+radioButtons[x]+'"]:checked','#test').attr('id'));
alert("Value is " + $('input[name = "'+radioButtons[x]+'"]:checked','#test').val());
}
}
}
</script>
</html>
這是需要在單擊按鈕或單選按鈕,單擊? – Samir
如果情況不正確,我認爲你。 – Samir
你需要添加引用jQuery庫 – Satpal