当前位置: 首页 > 图文教程 > 网络编程 > Javascript > JavaScript有趣实例:胸罩罩杯尺寸计算器

Javascript
编辑浪子版表单验证类
JavaScript脚本语言在网页中的简单应用
getElementById在任意一款浏览器中都可以用吗的疑问回复
“增强js程序代码的健壮性”之我见大量示例代码
javascript之卸载鼠标事件的代码
静态页面下用javascript操作ACCESS数据库(读增改删)的代码
javascript操作文本框readOnly
用javascript实现gb2312转utf-8的脚本
网站被黑的假象--ARP欺骗之页面中加入一段js
(JS实现)MapBar中坐标的加密和解密的脚本
几款极品的javascript压缩混淆工具
[原创]由亿起发(eqifa.com)的页面发现顶部的http://16a.us/8.js想到的js解密
JavaScript中的new的使用方法与注意事项
分别用两个函数实现的菜单
非常不错的模拟打字效果,目前仅支持纯文本、BR标签、和P标签
用javascript实现的支持lrc歌词的播放器
JS加ASP二级域名转向的代码
效果直逼flash的Div+Css+Js菜单
input之怎么清除默认值
用xhtml+css写的相册自适应 - 类似九宫格[兼容 ff ie6 ie7 opear ]

Javascript 中的 JavaScript有趣实例:胸罩罩杯尺寸计算器


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-28   浏览: 335 ::
收藏到网摘: n/a

  JavaScript出能能为网页添加更多互动元素、为网页的视觉效果锦上添花之外,还能干些什么?今天这个答案也许会出乎你的意料,外国一位设计师Ed Spencer用JavaScript为一个内衣网站编写了胸罩罩杯尺寸计算器。我们在使用JavaScript完成日常工作之余,其实也能编写这种有趣的程序。

  只在周末放松一下。

  近来Ed Spencer为一个更具诱惑性网站中的一个工作,这家网站是专卖女性内衣的。 除了不得不一整天去看只穿内衣的女人的图片这个不值得羡慕的任务之外,Ed Spencer还被迫去写一个胸罩尺寸计算器。

  胸罩尺寸计算器背后的理论是有点神秘和神奇了。 让一个男人或野兽理解它并不容易,所以它是幸运的,Ed Spencer完全不属于那两类, 他通过了痛苦和折磨的考验节省了广大女性的麻烦。

  下面来学习学习这个JavaScript有趣实例吧…

  这里是JS源文件,点击查看

代码如下:

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;
    }
};

点击这里使用胸罩罩杯尺寸计算器

英文原文:JavaScript Bra Size Calculator