<style type="text/css">
#txt_cm1, #txt_inch1, #txt_inch2, #txt_cm2 {
width: 63px;
height: 26px;
margin: 0 5px;
border: solid 1px #ccc;
}
#txt_inch1, #txt_cm2 {
background: #e7e7e7;
text-align: right;
padding-right: 5px;
width: 58px;
}
.converterCalculation{
overflow: hidden;
border: 1px solid #e7e7e7;
padding: 15px;
}
.converterCalculation .calculation{
color: #000;
height: 33px;
font-weight: bold;
width: 365px;
padding-right: 0;
}
.converterCalculation div.calculation input.last {
height: 26px;
line-height: 26px;
color: #fff;
background: #999;
padding: 0 5px;
margin-left: 5px;
}
</style>
<div class="converterCalculation">
<div class="calculation">Converter:
<input type="text" id="txt_cm1" onkeypress="keyPress(this)" onkeyup="keyUp(this)" onblur="onBlur(this)" />cm&nbsp;&nbsp;
<input type="text" id="txt_inch1" disabled="disabled" value="0.00" />inch
<input type="button" class="last" value="Calculation" onclick="Calculation(1)" />
</div>
<div class="calculation">Converter:
<input type="text" id="txt_inch2" onkeypress="keyPress(this)" onkeyup="keyUp(this)" onblur="onBlur(this)" />inch
<input type="text" id="txt_cm2" disabled="disabled" value="0.00" />cm&nbsp;&nbsp;
<input type="button" class="last" value="Calculation" onclick="Calculation(2)" />
</div>
</div>
<script type="text/javascript"> function keyPress(that){
that.value.match(/^[\+\-]?\d*?\.?\d*?$/)?that.t_value=that.value:that.value=that.t_value;
that.value.match(/^(?:[\+\-]?\d+(?:\.\d+)?)?$/)&&(that.o_value=that.value)
}
function keyUp(that){
that.value.match(/^[\+\-]?\d*?\.?\d*?$/)?that.t_value = that.value:that.value = that.t_value;
that.value.match(/^(?:[\+\-]?\d+(?:\.\d+)?)?$/) && (that.o_value=that.value)
}
function onBlur(that){
that.value.match(/^(?:[\+\-]?\d+(?:\.\d+)?|\.\d*?)?$/)?(
that.value.match(/^\.\d+$/)&&
(that.value=0+that.value),that.value.match(/^\.$/)&&
(that.value=0),that.o_value=that.value
):that.value = that.o_value
}
function Calculation(type){
var cm1,inch1,inch2,cm2;
type==1 && (
cm1=eval($("#txt_cm1").val()),
cm1==undefined&&(cm1=0),inch1=(cm1/2.54).toFixed(2),
$("#txt_inch1").val(inch1)
);
type==2 && (
inch2=eval($("#txt_inch2").val()),
inch2==undefined&&(inch2=0),cm2=(inch2*2.54).toFixed(2),
$("#txt_cm2").val(cm2)
)
}
</script>

js厘米与英寸尺码转换的更多相关文章

  1. js中实现字母大小写转换

    js中实现字母大小写转换主要用到了四个js函数: 1.toLocaleUpperCase  2.toUpperCase3.toLocaleLowerCase4.toLowerCase 下面就这四个实现 ...

  2. JS中的进制转换

    1 前言 js的进制转换, 分为2进制,8进制,10进制,16进制之间的相互转换, 我们直接利用 对象.toString()即可实现. 仅作为记录. 2 代码 //10进制转为16进制 (10).to ...

  3. ajax-json,遇到的一个问题,jquery var ,加载顺序。JS对象,json格式转换。

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. js数组,字符串,json互相转换函数有哪些

    js数组,字符串,json互相转换函数有哪些 一.总结 一句话总结: JSON.stringify(arr) JSON.parse(jsonString) str.split('') array.jo ...

  5. JS的类型转换,强制转换和隐式转换

    JS的类型转换 1.强制转换 通过String(),Number(),Boolean()函数强制转换 var str=123; var str1='123'; console.log(typeof s ...

  6. libs/tools.js stringToDate dateToString 日期字符串转换函数

    libs/tools.js stringToDate dateToString 日期字符串转换函数 import { stringToDate } from '@/libs/tools.js'   e ...

  7. 前端(十七)—— jQuery基础:jQuery的基本使用、JQ功能概括、JS对象与JQ对象转换、Ajax简单应用、轮播图

    jQuery的基本使用.JQ功能概括.JS对象与JQ对象转换.Ajax简单应用.轮播图 一.认识jQuery 1.什么是jQuery jQuery是对原生JavaScript二次封装的工具函数集合 j ...

  8. 使用 js 实现一个中文自动转换成拼音的工具库

    使用 js 实现一个中文自动转换成拼音的工具库 中文 => zhong-wen 应用场景 SEO 友好, URL 自动转换 blogs 发布文章,自动化部署,自动生成 url 的 path (时 ...

  9. c# 刻度:毫米 英寸 像素转换

    从目前所掌握的资料来看,c#程序中将毫米转换像素的方法无非两种: 第一种: 1: /// <summary> 2: /// 以毫米为单位的显示宽度 3: /// </summary& ...

随机推荐

  1. 【bzoj4423】 AMPPZ2013—Bytehattan

    http://www.lydsy.com/JudgeOnline/problem.php?id=4423 (题目链接) 题意 给出一个N*N的格点图,m次操作,每次切断U,V之间的边,问切断之后,U, ...

  2. Python 【第九章】 Django基础

    在windows 命令行上安装Django 在CMD命令行中输入以下命令进行安装. pip install Django 在windows python安装目录上会出现 一个django-admin. ...

  3. 修改pip更新源

    修改pip更新源 pip安装时默认访问pypi的,但是pypi的速度对于国内来说有点慢,还在国内也有一些pip的镜像源,造福广大程序员 pipy国内镜像目前有: http://pypi.douban. ...

  4. C# HttpWebRequest获取COOKIES

    C# HttpWebRequest获取COOKIES byte[] bytes = Encoding.Default.GetBytes(_post); CookieContainer myCookie ...

  5. Linux下安装 MySQL

    Ubuntu环境 使用二进制安装包安装,相对简单绿色 1.到官网下载二进制压缩包http://dev.mysql.com/downloads/mysql/ 2.选择需要的版本 目前最新为5.7.之后选 ...

  6. ruby 基础知识(二)

    ruby  中的动态方法 http://singleant.iteye.com/blog/1680382 Rails 大量使用了符号(symbol).符号看上去很像变量名,不过以冒号作为前缀.符号的例 ...

  7. RabbitMQ修改端口号和心跳时间

    定读者正在Windows系列的操纵体系中装置好了Rabbit MQ后,请找到装置途径下的etc文件夹下,将rabbitmq.config.example备份一份,并点窜为config范例的文件,即为] ...

  8. Windows无法完成安装,若要在此计算机上安装Windows,请中心启动安装。

    现在安装系统已经很简单了,我觉得U盘启动的话两步就差不多了, 壹:设置BIOS,将U盘启动作为系统默认启动选项 贰:直接进去大白菜之类的,一键安装... 今天终于看到第三部了, 报错:Windows无 ...

  9. 关于MapReduce中自定义分区类(四)

    MapTask类 在MapTask类中找到run函数 if(useNewApi){       runNewMapper(job, splitMetaInfo, umbilical, reporter ...

  10. JS事件的三种方式

    1.直接在元素上绑定回调函数 <button id="btn" onclick="clickBtn()">click me</button&g ...