我只知道一點Java和PHP。我想知道,是否有可能,例如,「IF radiobutton1 AND Radiobutton2 AND radiobutton3 AND radiobutton4 is click」,然後textbox1的值爲10. else IF radiobutton1 AND Radiobutton2 AND radiobutton5 AND radiobutton6 is click then textbox2的值是20" ?我想要做這樣的事情。if else。 JavaScript的。在文本框中顯示結果
我的代碼是在這裏和輸出:
<html>
<head>
<title>Belle</title>
<script language="javascript" type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
</head>
<body style="margin: 0; border: 0;">
<table border=0 align="center">
<th colspan="3"><h2><font color="black"
<th>
</font></h2></th>
<tr><td>
<table border="0" bordercolorlight="#FFFF99">
<th align="center" colspan="3" bgcolor="black"><font color="white">FIRST</font></th>
<tr><td> </td><td> </td><td> </td></tr>
<tr>
<td><input type="radio" name="flight" value="tnternational">International</td >
<td><input type="radio" name="flight" value="Domestic">Domestic</td >
</tr>
<tr><td> </td><td> </td><td> </td></tr>
<th align="center" colspan="3" bgcolor="black"><font color="white">SECOND</font></th>
<tr><td> </td><td> </td><td> </td></tr>
<tr>
<td>Type:</td>
<form action="javascript:return true;" name="form1">
<td><input type="radio" name="group1" value="opt1" id="opt1" onclick="show()"><label for="opt1">One Way</label></td>
<td><input type="radio" name="group1" value="opt2" id="opt2" onclick="show()"><label for="opt2">Round Trip</label></td>
</tr>
<tr>
<td>Insurance:</td>
<td><input type="radio" id="m1" name="insurance" value='250'/>Yes</td>
<td><input type="radio" id="m2" name="insurance" value='0'/>No</td>
</tr>
<tr><td> </td><td> </td><td> </td></tr>
<th align="center" colspan="3" bgcolor="black"><font color="white">THIRD</font></th>
<tr><td> <td> </td><td> </td></td><td >
<tr>
<td> </td>
<td><center>One</center></td>
<td><center>Two</center></td>
</tr>
<tr>
<td>
B:</br></br></br></br></br></br>
S1: </br></br></br></br>
S2:</br></br>
H: </br></br>
I:</br></br>
</td>
<td>
<input type="radio" value="0" name="bgto">None<br/>
<input type="radio" value="201.60" name="bgto">10kg<br/>
<input type="radio" value="201.60" name="bgto">15kg<br/>
<input type="radio" value="336.00" name="bgto">20kg<br/>
<input type="radio" value="672.00" name="bgto">30kg<br/>
<input type="radio" value="1232.00" name="bgto">45kg<br/>
<input type="radio" value="0" name="ssto">None<br/>
<input type="radio" value="257.60" name="ssto">Premium<br/>
<input type="radio" value="145.60" name="ssto">Standard<br/>
<input type="radio" value="1120.00" name="seto">Yes<br/>
<input type="radio" value="0" name="seto">No<br/>
<input type="radio" value="50" name="hmto">Yes<br/>
<input type="radio" value="50" name="hmto">No<br/>
<input type="radio" value="336" name="infto">Yes<br/>
<input type="radio" value="0" name="infto">No<br/>
</td>
<td><div id="from">
<input type="radio" value="opt2" name="bgfrom">None<br/>
<input type="radio" value="opt2" name="bgfrom">10kg<br/>
<input type="radio" value="opt2" name="bgfrom">15kg<br/>
<input type="radio" value="opt2" name="bgfrom">20kg<br/>
<input type="radio" value="opt2" name="bgfrom">30kg<br/>
<input type="radio" value="opt2" name="bgfrom">45kg<br/>
<input type="radio" value="opt2" name="ssfrom">None<br/>
<input type="radio" value="opt2" name="ssfrom">Premium<br/>
<input type="radio" value="opt2" name="ssfrom">Standard<br/>
<input type="radio" value="opt2" name="ssfrom">Stan-Plus<br/>
<input type="radio" value="opt2" name="sefrom">Yes<br/>
<input type="radio" value="opt2" name="sefrom">No<br/>
<input type="radio" value="opt2" name="hmfrom">Yes<br/>
<input type="radio" value="opt2" name="hmfrom">No<br/>
<input type="radio" value="opt2" name="inffrom">Yes<br/>
<input type="radio" value="opt2" name="inffrom">No<br/>
</div></td>
</tr>
</td></form>
</table>
<br/>
<td> </td>
<td>
<table border="0" bordercolorlight="BLACK">
<th align="center" colspan="2" bgcolor="bLACK"><font color="white">CALCULATE</font></th>
<tr><td> </td><td> </td></tr>
<form name="frmMain">
<tr><td>F: </td><td><input type="text" name="txtNumberA" value="0"> </td></tr>
<tr><td>I: </td><td><input type="text" id="txtNumberB" name="txtNumberB" value=""> </td></tr>
<tr><td>B: </td><td><input type="text" id="txtNumberD" name="txtNumberD" value=""> </td></tr>
<tr><td>S1: </td><td><input type="text" id="txtNumberE" name="txtNumberE" value=""> </td></tr>
<tr><td>S2: </td><td><input type="text" id="txtNumberF" name="txtNumberF" value=""> </td></tr>
<tr><td>H: </td><td><input type="text" id="txtNumberG" name="txtNumberG" value=""> </td></tr>
<tr><td>I: </td><td><input type="text" id="txtNumberH" name="txtNumberH" value=""> </td></tr>
<tr><td>TOTAL:</td><td><input type="text" name="txtNumberC" value=""> </td></tr>
<tr>
<td><input type="button" name="btnSum" value="TOTAL" OnClick="fncSum();"></td>
<td align="center"> </td>
</form>
</tr>
<tr><td> </td><td> </td></tr>
<script type="text/javascript">
(function($)
{
$(function()
{
$('input[type="radio"]').click(function(e)
{
value = $("input[name=insurance]:checked").val();
$('#txtNumberB').val(value);
});
});
})(jQuery);
</script>
<script type="text/javascript">
(function($)
{
$(function()
{
$('input[type="radio"]').click(function(e)
{
value = $("input[name=bgto]:checked").val();
$('#txtNumberD').val(value);
});
});
})(jQuery);
</script>
<script type="text/javascript">
(function($)
{
$(function()
{
$('input[type="radio"]').click(function(e)
{
value = $("input[name=ssto]:checked").val();
$('#txtNumberE').val(value);
});
});
})(jQuery);
</script>
<script type="text/javascript">
(function($)
{
$(function()
{
$('input[type="radio"]').click(function(e)
{
value = $("input[name=seto]:checked").val();
$('#txtNumberF').val(value);
});
});
})(jQuery);
</script>
<script type="text/javascript">
(function($)
{
$(function()
{
$('input[type="radio"]').click(function(e)
{
value = $("input[name=hmto]:checked").val();
$('#txtNumberG').val(value);
});
});
})(jQuery);
</script>
<script type="text/javascript">
(function($)
{
$(function()
{
$('input[type="radio"]').click(function(e)
{
value = $("input[name=infto]:checked").val();
$('#txtNumberH').val(value);
});
});
})(jQuery);
</script>
<script>
var dl = document.getElementById('from');
dl.style.visibility = 'hidden';
function show()
{
for (var i=0; i < document.form1.group1.length; i++)
{
if (document.form1.group1[i].checked)
{
var radio = document.form1.group1[i].value;
}
}
if (radio == 'opt2')
{
dl.style.visibility = 'visible';
}
else
{
dl.style.visibility = 'hidden';
}
}
</script>
<script>
function calculate_total(className, total_text)
{
var elements = document.getElementsByTagName("input");
var total = 0;
for(var i = 0; i < elements.length; ++i)
{
if(elements[i].className == className)
{
total += parseInt(elements[i].value);
}
}
document.getElementById(total_text).innerHTML = "Total: " + total;
}
</script>
<script>
function fncSum()
{
if(isNaN(document.frmMain.txtNumberA.value) || document.frmMain.txtNumberA.value == "")
{
alert('(Number A)Please input Number only.');
document.frmMain.txtNumberA.focus();
return;
}
if(isNaN(document.frmMain.txtNumberB.value) || document.frmMain.txtNumberB.value == "")
{
alert('(Number B)Please input Number only.');
document.frmMain.txtNumberB.focus();
return;
}
if(isNaN(document.frmMain.txtNumberD.value) || document.frmMain.txtNumberD.value == "")
{
alert('(Number D)Please input Number only.');
document.frmMain.txtNumberD.focus();
return;
}
if(isNaN(document.frmMain.txtNumberE.value) || document.frmMain.txtNumberE.value == "")
{
alert('(Number E)Please input Number only.');
document.frmMain.txtNumberE.focus();
return;
}
if(isNaN(document.frmMain.txtNumberF.value) || document.frmMain.txtNumberF.value == "")
{
alert('(Number F)Please input Number only.');
document.frmMain.txtNumberF.focus();
return;
}
if(isNaN(document.frmMain.txtNumberG.value) || document.frmMain.txtNumberG.value == "")
{
alert('(Number G)Please input Number only.');
document.frmMain.txtNumberG.focus();
return;
}
if(isNaN(document.frmMain.txtNumberH.value) || document.frmMain.txtNumberH.value == "")
{
alert('(Number H)Please input Number only.');
document.frmMain.txtNumberH.focus();
return;
}
document.frmMain.txtNumberC.value = parseFloat(document.frmMain.txtNumberA.value) +
parseFloat(document.frmMain.txtNumberB.value) +
parseFloat(document.frmMain.txtNumberD.value) +
parseFloat(document.frmMain.txtNumberE.value) +
parseFloat(document.frmMain.txtNumberF.value) +
parseFloat(document.frmMain.txtNumberG.value) +
parseFloat(document.frmMain.txtNumberH.value);
}
</script>
</body>
</html>
對我來說最好的方法是:第一。閱讀文檔;第2位。嘗試一些代碼;沒有這些任何答案將是一個廢話... – i100