gpt4 book ai didi

javascript - 将 slider 更改为选择框

转载 作者:行者123 更新时间:2023-11-30 16:57:46 24 4
gpt4 key购买 nike

我在尝试弄清楚如何将我的 bmi 计算器从幻灯片更改为选择框,然后传递该输入以进行计算时遇到问题。

对于脚,我将英寸设置为值,然后当选择英寸时,需要将它们添加到脚上以获得总计。

    <div class="form-group">
<label for="height-ft">Feet</label>
<select name="height-ft" id="height-ft" class="form-control">
<option value="12">1'</option>
<option value="24">2'</option>
<option value="36">3'</option>
<option value="48">4'</option>
<option value="60">5'</option>
<option value="72">6'</option>
<option value="84">7'</option>
</select>
</div>

<div class="form-group">
<label for="height-in">Inches</label>
<select name="height-in" id="height-in" class="form-control">
<option value="1">1"</option>
<option value="2">2"</option>
<option value="3">3"</option>
<option value="4">4"</option>
<option value="5">5"</option>
<option value="6">6"</option>
<option value="7">7"</option>
<option value="8">7"</option>
<option value="9">9"</option>
<option value="10">7"</option>
<option value="11">7"</option>
</select>
</div>

JS fiddle :使用 jquery ui 幻灯片的工作示例。 http://jsfiddle.net/ypyxrks8/

任何帮助转换它的人都将不胜感激。

最佳答案

你基本上已经做到了。该 slider 正在做一些事情来获取值,但您可以使用 parseInt() 获取值。我必须添加一个转换因子才能使其正确,您需要填写离散的重量值,但这是代码:

[HTML]

<div class="container">
<div class="row">
<div class="col-md-12"> <strong>Height:</strong>

<div class="form-group">
<select name="height-ft" id="height-ft" class="form-control">
<option value="12">1'</option>
<option value="24">2'</option>
<option value="36">3'</option>
<option value="48">4'</option>
<option value="60">5'</option>
<option value="72">6'</option>
<option value="84">7'</option>
</select>
</div>
<div class="form-group">
<select name="height-in" id="height-in" class="form-control">
<option value="1">1"</option>
<option value="2">2"</option>
<option value="3">3"</option>
<option value="4">4"</option>
<option value="5">5"</option>
<option value="6">6"</option>
<option value="7">7"</option>
<option value="8">7"</option>
<option value="9">9"</option>
<option value="10">10"</option>
<option value="11">11"</option>
</select>
</div>
</div>
<div class="col-md-12"> <strong>Weight:</strong>

<select name="weight-in" id="weight-in" class="form-control">
<option value="100">100</option>
<option value="120">120</option>
<option value="140">140</option>
<option value="160">160</option>
<option value="180">180</option>
<option value="200">200</option>
<option value="220">220</option>
<option value="240">240</option>
<option value="260">260</option>
<option value="280">280</option>
<option value="300">300</option>
</select>
<br>
</div>
<div type="button" id="calculatebutton" class="btn btn-primary">Calculate</div>
<div id="result"></div>
</div>

[CSS]

/* BMI Calculator */

$('#calculatebutton').click(function () {
var weight = parseInt($('#weight-in').val()),
heightInches = parseInt($('#height-ft').val()) + parseInt($('#height-in').val()),
heightsqaured = (heightInches) * (heightInches),
result = ((weight) / (heightsqaured) * 703);
debugger;
if (result < 16) {
var rating = ('You are severely underweight');
} else if (result > 16 && result < 18.5) {
var rating = ('You are underweight');
} else if (result > 18.5 && result < 25) {
var rating = ('You are healthy');
} else if (result > 25 && result < 30) {
var rating = ('You are overweight');
} else if (result > 30 && result < 35) {
var rating = ('You are moderately obese');
} else if (result > 35 && result < 40) {
var rating = ('You are severely obese');
} else if (result > 40 && result < 80) {
var rating = ('You are very severely obese');
} else if (result > 80) {
var rating = ('This result seems unlikely, please check that the information you have entered is correct');
}
$('#result').html('Your BMI is ' + result.toFixed(1) + '. ' + rating + '.');

});

这里的工作版本:https://jsfiddle.net/W3AVE/ypyxrks8/7/

关于javascript - 将 slider 更改为选择框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29396948/

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