我認爲錯誤是本着var gender=$("input[name='gender']:radio").val();
性別值不正確顯示
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
$(document).ready(function()
{
`$` character is just a shortcut for `window.jQuery`.
$("#sub").click(function()
{
/*fetch username
password*/
var u= $("input:text").val();
var pa=$("input:password").val();
var courses=[];
$.each($("input:checked"),function()
{
courses.push($(this).val());
});
//fetching gender value
var gender=$("input[name='gender']:radio").val();
//gender value not display correctly
$("p").html(**"Username**:"+*u*+"**Password:**"+pa+**"Course** **selected:**"+*courses.join(",")*+"**Gender**"+*gender*);
});
});
</script>
</head>
<body>
<form onsubmit="javascript:return false;">
Username<input type ="text" name="uname" >
Password<input type="password" name="pass" >
Course:
java<input type="checkbox" name="java" value="java">
Php<input type="checkbox" name="php" value="php">
.net<input type="checkbox" name=".net" value=".net">
javascript<input type="checkbox" name="javascript" value="javascript">
Gender:
Male<input type="radio" name="gender" value="male">
Female<input type="radio" name="gender" value="female">
<button id="sub">Submit</button>
</form>
<p></p>
</body>
</html>
不,它不工作..當我選擇:女性比它總是顯示男性...並且它也顯示選定的過程中的性別值也 – user4785724
更新嘗試它。只是要確保'$字符只是window.jQuery.'的快捷方式應該被註釋掉。 – bipen
是的,我從那裏刪除它,但它從那裏,但它再次顯示我一樣的錯誤。請給我發送正確的代碼 – user4785724