我有一个问题来检测选项选择,而不是使用 getElementById 我想使用 getElementByValue。它存在吗?这是我的代码
<script type="text/javascript">
var total;
function oneway(){
document.getElementById("return_date").style.visibility = "hidden";
document.getElementById("return_time").style.visibility = "hidden";
}
function return_way(){
document.getElementById("return_date").style.visibility = "visible";
document.getElementById("return_time").style.visibility = "visible";
}
function state_price(){
var way=document.getElementById("direction").value;
var placefrom = document.getElementById("state_from").value;
var placeto = document.getElementById("state_to").value;
if (direction == "oneway"){
if ((placefrom=="Batu Pahat" && placeto=="Alor Setar") ||(placefrom =="Alor Setar" && placeto=="Batu Pahat")){
total=55.00;
document.booking.total_price.value = total;
}else if ((placefrom=="Batu Pahat" && placeto=="Bachok")||(placefrom=="Bachok" && placeto=="Batu Pahat"))
{
total=60.00;
document.booking.total_price.value = total;
}else if ((placefrom=="Batu Pahat" && placeto=="A Famosa") || (placefrom=="A Famosa" && placeto=="Batu Pahat"))
{
total=65.50;
document.booking.total_price.value = total;
}else if ((placefrom=="Batu Pahat" && placeto=="Bahau")||(placefrom=="Bahau" && placeto=="Batu Pahat"))
{
total=70.00;
document.booking.total_price.value = total;
}else if ((placefrom=="Batu Pahat" && placeto=="Bentong") ||(placefrom=="Bentong" && placeto=="Batu Pahat"))
{
total=75.50;
document.booking.total_price.value = total;
}else if ((placefrom=="Batu Pahat" && placeto=="Kubang Kerian") ||(placefrom=="Kubang Kerian" && placeto=="Batu Pahat"))
{
total=80.00;
document.booking.total_price.value = total;
}
else
{
document.booking.txttotal.value = "Fail";
window.alert("Please enter a different destination");
}
}
else
{
///something else
}
}
</script>
这是我的 html 编码的一部分
<tr >
<td>Travel Direction:</td>
<td >
<input type="radio" name ="direction" value = "oneway" onclick = "oneway()"/>One Way
<input type="radio" name ="direction" value = "return" onclick = "return_way()"/>Return
</td>
</tr>
我不想使用这个名称,因为我在我的 php 编码中使用它。所以我不想使用它。有什么方法可以像上面提到的那样做我的 javascript (getElementByValue)?谢谢提前