jQuery 库未正确导入,单击按钮时表单未在 BAC 字段中显示答案。从这一点来看,答案应该是比较简单的。请检查 BAC 字段的显示代码。
<html>
<head>
<meta charset="utf-8" />
<title>bac2</title>
</head>
<body>
<p></p>
<form action="" id="bacForm">
<input type="radio" name="gender" value="male" /> Male<br /><br>
<input type="radio" name="gender" value="female" /> Female<br><br>
Weight <input type="text" name="weight" id="weight"/><br><br>
Hours <input type="text" name="hours" id="hours" /><br><br>
Drinks <input type="text" name="drinks" id="drinks"/><br><br>
<INPUT TYPE="button" value="submit" name="submit"><br><br>
BAC: <input type="text" name="bac" id="bac"/>
</form>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script>
<script type="text/javascript">
$('#submit').click(function(){
var gender = $('input[name=gender]:checked', '#bacForm').val();
var weight = parseInt($('#weight').val()) || 0;
var hours = parseInt($('#hours').val()) || 0;
var drinks = parseInt($('#drinks').val()) || 0;
var bac = 0;
if (gender=="male"){
bac = ((drinks * .06 * 100 * 1.055) / (weight * .68)) - (0.015 * hours);
}else if(gender=="female"){
bac = ((drinks * .06 * 100 * 1.055) / (weight * .55)) - (0.015 * hours);
}
$('#bac').val(bac);
});
</script>
</body>
</html>