如何使用Html与Jquery一起检查条件? [英] How Do I Check Conditions Using if else using Html With Jquery?

查看:49
本文介绍了如何使用Html与Jquery一起检查条件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<HTML>
<HEAD>
<TITLE> "CALCULATE FUEL COST" </TITLE>
<SCRIPT LANGUAGE = "JavaScript">
function fuelCalculator() {
var costpergallon;
costpergallon= (document.form1.ppg.value / (100 - document.form1.my_select.value))*100 / 12 // document.form1.mpg.value;
document.form1.cpg.value = costpergallon;
//document.write(costpergallon);
}
</script>
</head>
<Body>
Sampath Bank
<form name ="form1">
Amount :<input type="text" name="ppg" value=0 /> </br>
Installments : <select id="my_select" name="my_select">
  <option value="9.25">3</option>
  <option value="10.75">6</option>
  <option value="13.75">12</option>
  <option value="20.25">24</option>
  <option value="24.75">36</option>
  <option value="48">48</option>
  <option value="60">60</option>
</select> </br>
<input type="text" name="mpg" value=0 /> </br>
<input type="text" name="Airfare" value=0 /> </br>
<input type="text" name="AirlineTax" value=0 /> </br>
<input type="text" name="HotelExp" value=0 /> </br>
<input type="text" name="ToursExp" value=0 /> </br>
<input type="text" name="cpg" value=0 /> </br>
<input type= "button" value="Calculate" onclick="fuelCalculator();" />
</form>
</body>
</html>







这是我的代码?



i想放置if else条件。



if(my_select == 9.25){

var val1 = 12;

var total;

total = val1 * 9.25}



else

if(my_select == 10.75){

var val1 = 6;

var total;

total = val1 * 10.75}

}



我该怎么办?




this is my code?

i want to put if else condition.

if (my_select == 9.25){
var val1= 12;
var total;
total = val1*9.25 }

else
if (my_select == 10.75){
var val1= 6;
var total;
total = val1*10.75 }
}

How can i do that?

推荐答案

氏s不是最终解决方案,

因为不清楚你想要计算什么,

但是会告诉你如何从select标签中获取值:

This is not a final solution,
as it is not clear what you want to calculate,
but shall show you how to get the values from the select tag:
function fuelCalculator() {
    var input = document.getElementById('my_select');
    var value = input.options[input.selectedIndex].value;

    alert(value);

    var total = value * 12;

    alert(total);
}





希望这有助于您继续!



这不使用JQuery但是使用简单的javascript。

下面你找到了一个学习它的好资源:

http://www.w3schools.com/js/default.asp [ ^ ]


这篇关于如何使用Html与Jquery一起检查条件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆