Home > Web Front-end > JS Tutorial > js printing paper function code (recursive)_javascript skills

js printing paper function code (recursive)_javascript skills

WBOY
Release: 2016-05-16 18:24:52
Original
1171 people have browsed it
Copy code The code is as follows:

//Printing paper size, unit MM
//http: //en.wikipedia.org/wiki/ISO_216
var page = function() {
var A0 = { name: "A0", width: 841, height: 1189 }; //Unit MM
var B0 = { name: "B0", width: 1000, height: 1414 }; //Unit MM
var C0 = { name: "C0", width: 917, height: 1297 }; //Unit MM
//Get the previous specification
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);
}
}
//Get the specifications Size
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
}
} ();

Usage
Copy code The code is as follows:

page.getSize('A4 ')
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template