DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> 關於JavaScript >> js打印紙函數代碼(遞歸)
js打印紙函數代碼(遞歸)
編輯:關於JavaScript     
復制代碼 代碼如下:
//打印紙尺寸,單位MM
//http://en.wikipedia.org/wiki/ISO_216
var page = function() {
var A0 = { name: "A0", width: 841, height: 1189 }; //單位MM
var B0 = { name: "B0", width: 1000, height: 1414 }; //單位MM
var C0 = { name: "C0", width: 917, height: 1297 }; //單位MM
//獲取前一個規格
function getPrefixSize(name) {
var list = name.split('');
var series = list[0];
var number = parseInt(list[1]);
if (!isNaN(number) && number > 0) {
return series + (number - 1);
}
}
//獲取規格的尺寸
function getSize(name) {
if (name == "C7/6") {
return { name: "C7/6", width: 81, height: 162 };
}
var list = name.split('');
var series = list[0];
var number = parseInt(list[1]);
if (isNaN(number)) {
return;
}
if (number == 0) {
if (series == "A") { return A0; }
else if (series == "B") { return B0; }
else if (series == "C") { return C0; }
}
return { name: name, width: parseInt(getSize(getPrefixSize(name)).height / 2), height: parseInt(getSize(getPrefixSize(name)).width) };
}
return {
getSize: getSize
}
} ();

用法
復制代碼 代碼如下:
page.getSize('A4')
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved