gpt4 book ai didi

javascript - 单选按钮值未解析

转载 作者:行者123 更新时间:2023-11-28 16:23:49 26 4
gpt4 key购买 nike

我正在构建一个积分计算系统,该系统根据输入值计算积分。我在这个单选按钮上使用了一些 jquery ui 样式,但现在它总共没有加起来。代码太长,无法在此处发布,因此请检查此 live preview 。我通读代码很多次都找不到任何东西。

编辑:这是我的代码的精简版本:问题出在 div 第 2 部分中的单选按钮,请阅读我的评论。

    <html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Quebec and Federal Immigration Points Calculator</title>
<link rel="stylesheet" href="files/jquery00.css">
<link rel="stylesheet" href="files/flexselect.css">
<link rel="stylesheet" href="files/demos000.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js" type="text/javascript"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js" type="text/javascript"></script>
<script src="files/liquidmetal.js"></script>
<script src="files/jquery.flexselect.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$("select.flexselect").flexselect();
$( ".radio" ).buttonset();//here they are made into jquery ui buttonsets
$('#part1').show('slow', function() {
});
});
</script>
<script type="text/javascript">
function showAge(){
var d =document.getElementById('dob').value.split('/');
var today = new Date();
var bday = new Date(d[2],d[1],d[0]);
var age = today.getFullYear() - bday.getFullYear();
if(today.getMonth() < bday.getMonth() || (today.getMonth() == bday.getMonth() && today.getDate() < bday.getDate()))
{
t = age-1;
}
else {
t = age
}
document.getElementById('form').age.value = t;
}
</script>
<script type="text/javascript">
function compute(form)
{
var a = parseInt(document.getElementById('form').age.value, 10) || 0;
if ((18 <= a) && (a <= 35)){
q = 16;
}
else if (a == 36){
q = 14;
}
else if (a == 37){
q = 12;
}
else if (a == 38){
q = 10;
}
else if (a == 39){
q = 8;
}
else if (a == 40){
q = 6;
}
else if (a == 41){
q = 4;
}
else if (a == 42){
q = 2;
}
else if ((18 > a) || (a > 43)){
q = 0;
}
var b = parseInt(document.getElementById('form').highed.value, 10) || 0;
if (b == 1){
c = 0;
}
else if (b == 2){
c = 2;
}
else if (b == 3){
c = 4;
}
else if (b == 4){
c = 6;
}
var aos = parseInt(document.getElementById('form').selectareaofstudy.value, 10) || 0;
//here the value of the radiio button is parsed, and if nothing is selected it will default to zero
var tcfc2 = parseInt(document.getElementById('form').TCFC2.value, 10) || 0;
qt = (aos + c + q + tcfc2);
document.getElementById('total').age.value = q;
document.getElementById('total').ed.value = c;
document.getElementById('total').aos.value = aos;
document.getElementById('total').tcfc2.value = tcfc2;//here the value is displayed
document.getElementById('total').total.value = qt;//total displayed here
}
</script>
<script type="text/javascript">
function show2() {
$('#part1').hide('fast');
$('#part2').show('slow');
}
function back2() {
$('#part1').show('slow');
$('#part2').hide('fast');
}
function showTCF() {
if($('#radio1-1').is(':checked')) { alert("it's checked"); }
}
</script>
</head>
<body>
<div id="formbox">
<form id="form" name="form">
<div id="part1" style="display:none">
<div id="hidden">
<p>Your Date of Birth (format:<strong>dd/mm/yyyy</strong>)</p>
<br />
<input onBlur="compute(this.form)" onchange="showAge()" name="dob" id="dob" />
</div>
<p>Your Age</p>
<input class="sev" name="age" type="text" onMouseOver="compute(this.form)" style="font-size: 15px" value="" size="7" />
<h1>Your education</h1>
<h2>Your highest level of Education:</h2>
<select onchange="compute(this.form)" name="highed">
<option value="">Select One</option>
<option value="1">No high school diploma or general Professional</option>
<option value="2">High school general diploma +2 or 12th grade</option>
<option value="3">Postsecondary diploma 2 years general of full-time studies</option>
<option value="4">Postsecondary technical diploma 1 year of full-time studies</option>
<option value="4">Postsecondary technical diploma 2 years of full-time studies</option>
</select>
<h2>Your Area of Education:<small>(start typing..)</small></h2>
<select class="flexselect" name="selectareaofstudy">
<option value=""></option>
<option value="6">3D Animation and Image Synthesis Techniques (DCS - 3 years) </option>
<option value="6">LOADS OF OTHER VALUES HERE</option>
</select>
<br />
<br />
<INPUT class="ten" NAME="calc" VALUE="Calculate" TYPE="button" onClick="compute(this.form)">
&nbsp;&nbsp;
<INPUT class="ten" NAME="calc" VALUE="Next" TYPE="button" onClick="show2()">
<br />
</div>
<div id="part2" style="display:none">
<h2>French Proficiency</h2>
<p>Have you written: <strong>TCF Quebec/ TEFaQ/ TCF/ TEF level C2- DALF C2?</strong> </p>
<div id="radio1" class="radio">
<!--These radio buttons have values of 1 and 2 but when calculated they always show up as zero, the default values.-->
<input id="radio1-1" name="TCFC2" type="radio" value="1" checked="checked" />
<label for="radio1-1">Yes</label>
<input id="radio1-2" name="TCFC2" type="radio" value="2" />
<label for="radio1-2">No</label>
</div>
<br />
<br />
<br />
<INPUT class="ten" NAME="calc" VALUE="Calculate" TYPE="button" onClick="compute(this.form)">
&nbsp;&nbsp;
<table>
<tr>
<td><INPUT class="ten" NAME="calc" VALUE="Back" TYPE="button" onClick="back2()"></td>
<td><INPUT class="ten" NAME="calc" VALUE="Next" TYPE="button" onClick="show3()"></td>
</tr>
</table>
</div>
</form>
</div>
<div style="" id="totalmenu" class="port-menu-wrapper">
<form id="total">
<h3>Points For</h3>
<table>
<tr>
<td><label>Age</label></td>
<td><input class="sev" name="age" type="text" style="font-size: 15px" value="" size="7" readonly></td>
</tr>
<tr>
<td><label style="font-size: 18px">Your Education</label></td>
</tr>
<tr>
<td><label>Education 1</label></td>
<td><input class="sev" name="ed" type="text" style="font-size: 15px" value="" size="7" readonly></td>
</tr>
<tr>
<td><label>Area of Study</label></td>
<td><input class="sev" name="aos" type="text" style="font-size: 15px" value="" size="7" readonly></td>
</tr>
<tr>
<td><label style="font-size: 18px">French Proficiency</label></td>
</tr>
<tr>
<td><label>TCFC2</label></td>
<td><input class="sev" name="tcfc2" type="text" style="font-size: 15px" value="" size="7" readonly></td>
</tr>
<tr>
<td><label style="font-size:20px;"><strong>Total</strong></label></td>
<td><input class="ten" name="total" type="text" style="font-size: 20px" value="" size="10" readonly></td>
</tr>
</table>
</form>
</div>
</body>
</html>

最佳答案

我不认为它链接到jquery ui,而是链接到行

var tcfc2 = parseInt(document.getElementById('form').TCFC2.value, 10) || 0;

由于您有 2 个带有名为 TCFC2 的单选按钮的元素,因此将使用它们创建一个数组。此外,第一个 radio 的值始终为 1,第二个 radio 的值始终为 2。您需要检查“checked”属性,而不是确定人们是否讲法语的值。

var tcfc2 = document.getElementById('form').TCFC2[0].checked -0 ;

没有parseInt,因为返回“true”或“false”,“-0”是强制int转换。

最后,我会将 radio 或输入类型文本重命名为 TCFC2 之外的其他名称。 (并合并你的CSS,将脚本和样式从html文件中取出并放入它们自己的文件中以进行维护,并将你的变量命名为比a、b和c更有意义的名称......)

关于javascript - 单选按钮值未解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8707471/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com