只在周末放松一下 ;)
Ed Spencer 已经用JavaScript编了一个胸罩尺寸计算器 :
近来我为一个更具诱惑性网站中的一个工作,这家网站是专卖女性内衣的。 除了不得不一整天去看只穿内衣的女人的图片这个不值得羡慕的任务之外,我还被迫(强迫!)去写一个胸罩尺寸计算器。
胸罩尺寸计算器背后的理论是有点神秘和神奇了。 让一个男人或野兽理解它并不容易,所以它是幸运的,我完全不属于那两类, 我通过了痛苦和折磨的考验节省了您的麻烦。
var BraCalculator = {
/**
* The string to be returned when the result could not be calculated. Overwrite to change this
*/
unknownString: "Unknown",
cupSizes: ["A", "B", "C", "D", "DD", "E", "EE", "F", "FF", "G", "GG", "H", "HH",
"J", "JJ", "K", "KK", "L", "LL", "M", "MM", "N", "NN"],
/**
* Returns the correct bra size for given under bust and over bust measurements
* @param {Number} underBust The measurement taken under the bust (in inches)
* @param {Number} overBust The measurement taken over the bust (in inches)
* @return {String} The correct bra size for the given measurements (e.g. 32C, 40DD, etc)
*/
calculateSize: function(underBust, overBust) {
var bandSize = this.calculateBandSize(underBust);
var cupSize = this.calculateCupSize(bandSize, overBust);
if (bandSize && cupSize) {
return bandSize + cupSize;
} else {
return this.unknownString;
};
},
/**
* Calculates the correct band size for a given under bust measurement
* @param {Number} underBust The measurement under the bust
* @return {Number} The correct band size
*/
calculateBandSize: function(underBust) {
var underBust = parseInt(underBust, 10);
return underBust + (underBust % 2) + 2;
},
/**
* Calculates the Cup size required given the band size and the over bust measurement
* @param {Number} bandSize The measured band size (should be an even number)
* @param {Number} overBust The measurement taken over the bust
* @return {String} The appropriate alphabetical cup size
*/
calculateCupSize: function(bandSize, overBust) {
var bandSize = parseInt(bandSize, 10);
var overBust = parseInt(overBust, 10);
var diff = overBust - bandSize;
var result = this.cupSizes[diff];
//return false if we couldn't lookup a cup size
return result ? result : false;
}
};
And to apply it to your own pages, use something a bit like this:
jQuery(document).ready(function(){
//add listeners to band and cup measurement text boxes
jQuery('#back').keyup(Honeys.updateBraSizeCalculation);
jQuery('#cup').keyup(Honeys.updateBraSizeCalculation);
});
var Honeys = {
updateBraSizeCalculation: function() {
var back = jQuery('#back')[0].value;
var cup = jQuery('#cup')[0].value;
if (back.length > 0 && cup.length > 0) {
jQuery('#fit')[0].value = BraCalculator.calculateSize(back, cup);
};
}
};
分享到:
相关推荐
javascript白色简洁计算器
Javascript、CSS的简易科学计算器
用javascript编程语言编写的简易计算器,仅包含+-*/运算
学习了javascript ,这个代码是使用javascript来做一个简单的计算器,可以实现简单的额加减乘除的计算
javaScript简单模拟计算器简单易懂
用javascript做简单计算器,实现加减乘除的简单运算。
一个好用的科学计算器……
这是我用javascript写的一个计算器,效果类似于window xp自带的计算器
这个是一个界面比较好、而且比较简单地用javascript语言和html语言写的一个计算器,非常适合初学者
用js做的一个计算器,可以用这个方法去做一个Java代码
同事用javascript写的计算器,已经封装成对象了(带用例)。 调用起来很方便。
参考博客:http://blog.csdn.net/xiaowei_cqu/article/details/7081348
JAVA Script编写的计算器,界面较为简单,功能较少,可供初学者参考使用
本资源是一个网页形式的计算器,用javascript实现了+、-、*、/、求倒数、求模、以及求表达式的功能。代码简洁精练。
用纯javascript做的计算器,按键功能齐全,初级水平,用来交作业吧
JavaScript 中的计算器及其源代码 该计算器是一个使用 HTML5、CSS 和 JavaScript 编写的简单项目。 这里,计算器的功能与现实生活中的简单计算器一样。 该项目旨在解决数字的数学计算。 您可以在该项目中看到计算器...
javascript实现优先级计算器
本计算器是html+javascript的在线计算器。
javascript写的计算器,解决的JavaScript小数运算精度的损失
基于JavaScript实现网页计算器 本文实例为大家分享了JavaScript实现网页计算器的扫雷游戏的具体代码,供大家参考,具体内容如下 先看效果: 此外,计算器还附有数字、运算符检查功能: 下贴源码: <!DOCTYPE ...