Javascript / jQuery - 以英尺和英寸显示英寸 [英] Javascript/jQuery - Display inches in feet and inches

查看:98
本文介绍了Javascript / jQuery - 以英尺和英寸显示英寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作BMI计算器(请参阅JSFiddle - http://jsfiddle.net/b5ww2/ ),我希望英寸的高度以英尺和英寸显示。我还希望用磅和磅来显示体重。



这是我用来将滑块值转换为cm和inches的代码:

p>

  slide:function(event,ui){
$(#heightslidecm).html(ui.value +'厘米' );
$(#heightslidein).html((ui.value * 0.393700787).toFixed(0)+'in');
}

我的js知识不是很好 - 特别是在数学方面。

任何想法?



预先致谢

解决方案

您只需包含转换的逻辑即可。这是一个英尺和英寸的例子:

$ $ p $ $ $ $ $ $幻灯片:function(event,ui){
$(# heightslidecm).html(ui.value +'cm');

var inches =(ui.value * 0.393700787).toFixed(0);
var feet = Math.floor(inches / 12);
英寸%= 12;

$(#heightslidein).html(feet +ft+ inches +'in');





$ b你只需要用适当的逻辑重复磅/转化价值。


I'm making a BMI calculator (see JSFiddle - http://jsfiddle.net/b5ww2/) and I want the height in inches to display in feet and inches. I also want the weight in pounds to be displayed in stones and pounds.

This is the code I'm using to convert the slider value to cm and inches:

slide: function( event, ui ) {
  $( "#heightslidecm" ).html( ui.value + 'cm' );
  $( "#heightslidein" ).html( (ui.value*0.393700787).toFixed(0) + 'in' );
}

My js knowledge isn't great - especially when it comes to the math aspect.

Any ideas?

Thanks in advance

解决方案

You simply need to include the logic for the conversion. Here is an example for feet and inches:

slide: function( event, ui ) {
    $( "#heightslidecm" ).html( ui.value + 'cm' );

    var inches = (ui.value*0.393700787).toFixed(0);
    var feet = Math.floor(inches / 12);
    inches %= 12;

    $( "#heightslidein" ).html( feet + "ft " + inches + 'in');
}

You just need to repeat this same logic for the pounds/stone using the appropriate conversion values.

这篇关于Javascript / jQuery - 以英尺和英寸显示英寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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