我正在使用一些遺留(大約2003年)JavaScript和HTML代碼,並需要一些幫助分頁下面的代碼生成的HTML輸出。在JavaScript生成的HTML頁面分頁 - 不是爲了心灰意懶
要查看此實際情況 - 請訪問site,然後單擊容量選項卡。在每個字段中輸入值,然後單擊容量圖表按鈕。數字越大,輸出越大。我希望能夠將這個輸出用頁面中的30行分頁。
任何幫助將不勝感激。此外,目前在IE,谷歌瀏覽器和Safari瀏覽器中效果最好 - 我正在單獨制定Firefox的一個問題。
謝謝。
function CapacityChart()
{
if (parseInt(navigator.appVersion) >= 4)
{
var htmlcode = '';
var RUnits = Math.abs(document.all.Capacity.RUnits.value);
var LUnits = Math.abs(document.all.Capacity.LUnits.value);
var HUnits = Math.abs(document.all.Capacity.HUnits.value);
var radius = Math.abs(document.all.Capacity.VesRadius.value);
var height = Math.abs(document.all.Capacity.LiqHeight.value);
var length = Math.abs(document.all.Capacity.VesLength.value);
var units = eval(document.Capacity.RUnits.value);
var VUnits = Math.abs(document.all.Capacity.VUnits.value);
var capacity;
var unitlabel;
var divisor = 1;
var i;
//* Convert Height unit to inches
switch (document.all.Capacity.HUnits.selectedIndex){
case 0:
height = eval(height * 12)
unitlabel = 'Inches';
break;
case 1:
unitlabel = 'Inches';
break;
}
//* Convert RUnits to inches
switch (document.all.Capacity.RUnits.selectedIndex){
case 0:
radius = eval(radius * 12)
unitlabel = 'Inches';
break;
case 1:
unitlabel = 'Inches';
break;
}
//* Convert LUnits to inches
switch (document.all.Capacity.LUnits.selectedIndex){
case 0:
length = eval(length * 12);
unitlabel = 'Inches';
break;
case 1:
unitlabel = 'Inches';
break;
}
if(length > 0 && radius > 0){
s ='<HTML><HEAD><LINK REL="stylesheet" TYPE="text/css" HREF="bendelcorp.css"><SCRIPT LANGUAGE="Javascript" SRC="js/bendelcorp.js" TYPE="TEXT/JAVASCRIPT"></SCRIPT></HEAD><BODY>';
s += '<TABLE>';
s += '<TR><TD ALIGN="left" VALIGN="top" ROWSPAN="5"><IMG SRC="images/logo.png" ALT="logo" WIDTH="210" HEIGHT="118"></TD></TR><BR>';
s += '</TABLE><BR>';
s += '<SPAN CLASS="heading1">Capacity Chart</SPAN><BR><HR>';
s += '<TABLE ALIGN="center" WIDTH="80%"';
s += '<TR><TD ALIGN="left" VALIGN="top" COLSPAN="2">Inside dimensions</TD></TR>';
s += '<TR><TD ALIGN="right" VALIGN="top" ROWSPAN="5"><IMG SRC="images/tools_capacity.jpg" ALT="" WIDTH="172" HEIGHT="139"></TD><TD>Length: ' + document.all.VesLength.value + ' ' + document.all.LUnits.options[document.all.LUnits.selectedIndex].text + '</TD></TR>';
s += '<TR><TD>Radius: ' + document.all.Capacity.VesRadius.value + ' ' + document.all.LUnits.options[document.all.RUnits.selectedIndex].text + '</TD></TR>';
s += '<TR><TD>Height: (See Below) </TD></TR>';
s += '<TR><TD> </TD></TR>';
s += '<TR><TD>Volume: (See below) </TD></TR>';
s += '</TABLE>';
s += '<BR CLEAR="all"><HR>';
s += '<TABLE WIDTH="420" BORDER="1" CELLPADDING="2" CELLSPACING="0" ALIGN="center"';
s += '<TR><TD ALIGN="middle">Height (' + unitlabel + ')</TD><TD ALIGN="middle">Volume (' + document.Capacity.VUnits.options[document.Capacity.VUnits.selectedIndex].text + ')</TD></TR>';
for(i = 1; i <= (2 * radius); i++){
height = i;
//* alert('H:' + height + ' R:' + radius + 'L:' + length);
if (height > (radius * 2)){
height = 2 * (radius)
height = Math.round(height * 10)/10;
capacity = length * (Math.pow(radius,2) * Math.PI);
}
if (height == (2 * radius))
{
capacity = length * (Math.pow(radius,2) * Math.PI);
}
if (height > radius)
{
capacity = length * (Math.pow(radius,2) * Math.PI) - (length* Math.pow(radius,2)/2 * (2 * Math.acos((radius - ((2 * radius) - height))/radius) - Math.sin(2 * Math.acos((radius - ((2 * radius) - height))/radius))));
}
if (height == radius)
{
capacity = length * (Math.pow(radius,2) * Math.PI)/2;
}
if (height < radius)
{
capacity = length * Math.pow(radius,2)/2 * (2 * Math.acos((radius - height)/radius) - Math.sin(2 * Math.acos((radius - height)/radius)));
}
//* Convert capacity into selected units
switch (document.all.Capacity.VUnits.selectedIndex){
case 0:
capacity = eval(capacity /1728);
break;
case 1:
break;
case 2:
capacity = eval(capacity * .0000163871527);
break;
case 3:
capacity = eval(capacity * 16.387064);
break;
case 4:
capacity = eval(capacity * .016387064);
break;
case 5:
capacity = eval(capacity * 0.0043290040509);
break;
case 6:
capacity = eval(capacity * .000137428819);
break;
case 7:
capacity = eval(capacity * .000103071759);
break;
}
s += '<TR><TD ALIGN="middle">' + height + '</TD><TD ALIGN="middle">' + Math.round(capacity * 10)/10 + '</TD></TR>';
}
s += '</TABLE><BR CLEAR="all"><HR><TABLE ALIGN="center"';
s += '</TABLE></BODY></HTML>';
CapacityWindow = window.open('','CapacityWindow', 'toolbar=0,scrollbars=0,menubar=0,width=0,height=0');
CapacityWindow.close();
CapacityWindow = window.open('','CapacityWindow', 'toolbar,scrollbars,menubar,width=480,height=600');
CapacityWindow.document.write(s);
} else {
alert('Length and radius of vessel must be greater than 0.');
}
} else {
alert('This capability is only available with internet browsers that support JavaScript.')
}
}
+1爲標題/代碼組合,它使我的一天:)但還有更多!未完成的句子「這最好用」,承諾更多善意。讓我猜猜:在Netscape 4中最好的工作? :) – 2009-12-24 17:03:19
雖然我不明白你的意思是「輸出」。我能看到的唯一的事情就是表格,那已經分頁了,不是嗎? – 2009-12-24 17:04:50
不要笑。我之前說過這是遺留代碼,我正在嘗試使用它。是的,我點擊提交太快,但編輯完成它的條目。畢竟這是聖誕節前夕,輕鬆下去。 – fmz 2009-12-24 17:32:22