<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. 架构师养成记--12.Concurrent工具类CyclicBarrier和CountDownLatch

    java.util.concurrent.CyclicBarrier 一组线程共同等待,直到达到一个公共屏障点. 举个栗子,百米赛跑中,所有运动员都要等其他运动员都准备好后才能一起跑(假如没有发令员) ...

  2. Linux CentOS6.x ip设置(网卡设置)

    修改IP永久生效按以下方法vi /etc/sysconfig/network-scripts/ifcfg-eth0(eth0,第一块网卡,如果是第二块则为eth1)按如下修改ip: DEVICE=et ...

  3. add user and grant privileges on mariadb

    create database foo_db; create user foo_user identified by 'foo_password'; grant all on foo_db.* to ...

  4. matlab画图函数plot()/set/legend

    简单plot()/legend/XY轴范围axis 除了坐标轴信息外还可以添加其它的信息,如所画曲线的信息等:测试代码如下 x=0:pi/20:2*pi; y1=sin(x); y2=cos(x); ...

  5. datagrid

    <!DOCTYPE html><html><head> <style>body {  font-family: Helvetica Neue, Aria ...

  6. laypage分页

    1.分页 laypage({ cont:$("#page"), //容器,仅支持id名\原生DOM对象,jquery对象 pages:, //总页数 skip:true, //是否 ...

  7. ThinkPHP框架之验证码

    Think\Verify类可以支持验证码的生成和验证功能. 下面是最简单的方式生成验证码: $Verify = new \Think\Verify(); $Verify->entry(); 上面 ...

  8. p/invoke碎片,对结构体的处理

    结构体的一些相关知识 可直接转换类类型,比如int类型,在托管代码和非托管代码中占据内存大小 和意义都是一个样的. 结构体封送的关键是:在托管代码和非托管代码中定义的一致性.什么是定义的一致性?包括结 ...

  9. Linux下数据恢复软件extundelete

    extundelete软件专门解决意外删除事件的,有时候不小心 rm -rf * 就可能毁掉有用的数据.因此就出现了这个恢复工具,但这个工具也不是万能的,删除数据后一定要停止所以的写操作.以免Inod ...

  10. Linux服务管理