JavaScript公顷、亩和平方米的转换
分类:实例代码
JavaScript公顷、亩和平方米的转换属于前端实例代码,有关更多实例代码大家可以查看。
本章节分享一段代码实例,能够实现公顷、亩和平方米的相互转换效果。
代码实例如下:
<!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta name="author" content="http://www.pipipi.net/" /> <title>前端教程网</title> <script type="text/javascript"> window.onload=function(){ var a=parseInt('0'); var sel=document.getElementById('sel'); sel.selectedIndex=2-a; var lastUnit=document.getElementById('sel').value; var input=document.getElementById("input0"); var fRate={ 公顷:{亩:15,平方米:10000}, 亩:{平方米:10000/15,公顷:1/15}, 平方米:{亩:15 / 10000,公顷:1 / 10000} }; function selectChange(obj){ var v=parseFloat(input.value); var rst=(v * fRate[lastUnit][sel.value]).toFixed(4); input.value=rst; lastUnit=sel.value; } sel.onchange=function(){ selectChange(this) } } </script> </head> <body> <select id="sel"> <option value="公顷">公顷</option> <option value="亩">亩</option> <option value="平方米">平方米</option> </select> <input type="text" value="3" id="input0"/> </body> </html>
JavaScript公顷、亩和平方米的转换,这样的场景在实际项目中还是用的比较多的,关于JavaScript公顷、亩和平方米的转换就介绍到这了。