js厘米与英寸尺码转换
<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
<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
<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厘米与英寸尺码转换的更多相关文章
- js中实现字母大小写转换
js中实现字母大小写转换主要用到了四个js函数: 1.toLocaleUpperCase 2.toUpperCase3.toLocaleLowerCase4.toLowerCase 下面就这四个实现 ...
- JS中的进制转换
1 前言 js的进制转换, 分为2进制,8进制,10进制,16进制之间的相互转换, 我们直接利用 对象.toString()即可实现. 仅作为记录. 2 代码 //10进制转为16进制 (10).to ...
- ajax-json,遇到的一个问题,jquery var ,加载顺序。JS对象,json格式转换。
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- js数组,字符串,json互相转换函数有哪些
js数组,字符串,json互相转换函数有哪些 一.总结 一句话总结: JSON.stringify(arr) JSON.parse(jsonString) str.split('') array.jo ...
- JS的类型转换,强制转换和隐式转换
JS的类型转换 1.强制转换 通过String(),Number(),Boolean()函数强制转换 var str=123; var str1='123'; console.log(typeof s ...
- libs/tools.js stringToDate dateToString 日期字符串转换函数
libs/tools.js stringToDate dateToString 日期字符串转换函数 import { stringToDate } from '@/libs/tools.js' e ...
- 前端(十七)—— jQuery基础:jQuery的基本使用、JQ功能概括、JS对象与JQ对象转换、Ajax简单应用、轮播图
jQuery的基本使用.JQ功能概括.JS对象与JQ对象转换.Ajax简单应用.轮播图 一.认识jQuery 1.什么是jQuery jQuery是对原生JavaScript二次封装的工具函数集合 j ...
- 使用 js 实现一个中文自动转换成拼音的工具库
使用 js 实现一个中文自动转换成拼音的工具库 中文 => zhong-wen 应用场景 SEO 友好, URL 自动转换 blogs 发布文章,自动化部署,自动生成 url 的 path (时 ...
- c# 刻度:毫米 英寸 像素转换
从目前所掌握的资料来看,c#程序中将毫米转换像素的方法无非两种: 第一种: 1: /// <summary> 2: /// 以毫米为单位的显示宽度 3: /// </summary& ...
随机推荐
- python gettitle v2.0
#!/usr/bin/env python # coding=utf-8 import threading import requests import Queue import sys import ...
- 批量解密SQLSERVER数据库中的各种对象的工具dbForge SQL Decryptor
批量解密SQLSERVER数据库中的各种对象的工具dbForge SQL Decryptor2.1.11 之前写过一篇文章,使用redgate公司的SQL PROMPT工具,但是不太方便 SQLPRO ...
- 浅谈Android样式开发之View Animation (视图动画)
引言 一个用户体验良好的App肯定少不了动画效果.Android为我们提供了2种动画框架,分别是视图动画(View Animation)和属性动画(Property Animation).视图动画比较 ...
- .gitignore过滤个人配置
git还是一个很好使用的版本工具.所以用eclipse做自己的小玩意儿,在多台电脑之间同步的时候我经常会使用它.. 但是有个问题..不同电脑的eclipse的个人配置稍微有那么一点点的不同..比如有几 ...
- prototype,__proto__,constructor
proto属性: 所有对象都有此属性.但它不是规范里定义的属性,并不是所有JavaScript运行环境都支持.它指向对象的原型,也就是你说的继承链里的原型.通过Object.getPrototypeO ...
- 1、SQL Server自动化运维 - 备份(一)业务数据库
为了能够恢复数据,数据库运维基础就是备份,备份自动化也是运维自动化首要进行的. 笔者的备份自动化,通过配置表快速配置为前提,同时记录备份过程,尽可能的减少人工操作.首先将SQL Server备份按用途 ...
- x:Array的使用
x:Array是通过Items属性向使用者暴露一个类型已知的ArrayList.ArrayList中成员类型由x:Array type指明 <Window x:Class="demo_ ...
- Json在PHP与JS之间传输
1. JS-->PHP a). JS create Json <script> $(document).ready(function(){ /*--JS create Json--* ...
- Linq练习
首先在Program.cs的Main()方法下添加如下代码: string[] names = { "heh", "haha", "huahua&qu ...
- 【bzoj4721】[Noip2016]蚯蚓
题目描述 本题中,我们将用符号[c]表示对c向下取整,例如:[3.0」= [3.1」=[3.9」=3.蛐蛐国最近蚯蚓成灾了!隔壁跳蚤国的跳蚤也拿蚯蚓们没办法,蛐蛐国王只好去请神刀手来帮他们消灭蚯蚓.蛐 ...