我只知道一点Java和PHP。我想知道,有可能,例如,“IF radiobutton1 AND Radiobutton2 AND radiobutton3 AND radiobutton4点击然后textbox1的值是10.否则IF radiobutton1 AND Radiobutton2 AND radiobutton5 AND radiobutton6点击然后textbox2的值是20" ?我想做这样的事情。
我的代码在这里,输出:
<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>
答案 0 :(得分:1)
这个javascript示例可能是一个好的开始:
if (document.forms['myForm'].elements["radio1"].checked &&
document.forms['myForm'].elements["radio2"].checked &&
document.forms['myForm'].elements["radio5"].checked
)
{
document.forms['myForm'].elements["textbox2"].value = 10;
} else if (document.forms['myForm'].elements["radio3"].checked &&
document.forms['myForm'].elements["radio4"].checked &&
document.forms['myForm'].elements["radio7"].checked
)
{
document.forms['myForm'].elements["textbox2"].value = 20;
}
答案 1 :(得分:0)
通过jQuery
$('button').bind('click',function(){
if($('#a').is(':checked')&& $('#c').is(':checked')){
$('input').val('Sometext');
}
});
这是小提琴http://jsfiddle.net/Goodluck/eay96/ 我不知道你的情况是什么是自动的,但你也可以改变它:
$('.cb').change(function(){
if($('#a').is(':checked')&& $('#c').is(':checked')){
$('input').val('Sometext');
}
});
答案 2 :(得分:0)
<html>
<head>
<script language="javascript" type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
</head>
<body>
<table border="0" bordercolorlight="#FFFF99">
<form name="frmMain">
<th align="center" colspan="3" bgcolor="black"><font color="white">FIRST</font></th>
<tr><td colspan="3"><center><input type="radio" name="flight" value="International" class="flight" id="intl">International</td ></tr>
<th align="center" colspan="3" bgcolor="black"><font color="white">SECOND</font></th>
<tr><td>Type:</td>
<td colspan="2"><center><input type="radio" name="group1" value="opt1" id="opt1" onclick="show()" class="flight"><label for="opt1">One Way</label></td>
</tr>
<tr><td>I:</td>
<td colspan="2"><center><input type="radio" id="m1" name="insurance" value='0' class="flight"/>Yes
<input type="radio" id="m2" name="insurance" value='0' class="flight"/>No</td>
</tr>
<tr><td>I:</td><td><input type="text" id="txtNumberB" name="txtNumberB" value="0" class="flight"> </td></tr>
<script>
$('.flight').change(function(){
if($('#intl').is(':checked')&& $('#opt1').is(':checked')&& $('#m1').is(':checked'))
{
document.frmMain.txtNumberB.value = 250.00;
}
if($('#intl').is(':checked')&& $('#opt1').is(':checked')&& $('#m2').is(':checked'))
{
document.frmMain.txtNumberB.value = 0.00;
}
});
</script>
</html>
像这样:) :)谢谢你。