點擊“計算”為什么跳轉呢 ??? 而且跳轉的還是“該頁無法顯示”?
<script>
var focusflag = false;
var Factor = new Array(1);
Factor[0] = .3462;
var RoundOff = 5;
function UnitConvertI(value,type){
if(type=="aaa")
value = value/2.54;
if(type=="bbb")
value = (value*100)/2.54;
if(type== "ccc")
value = (value/10)/2.54;
if(type=="ddd")
value = value*12;
if(type=="eee")
value = value*36;
return value;
}
function UnitConvertF(value,type){
if(type== "aaa")
value = (value/2.54)/12;
if(type =="bbb")
value = ((value*100)/2.54)/12;
if(type=="ccc")
value = ((value/10)/2.54)/12;
if(type=="ddd")
value = value/12;
if(type=="eee")
value = value*3;
return value;
}
function CheckNum(value,label){
var String1 = new String(value);
var String2 = new String("");
var String3 = new String("");
var String4 = new String("");
var temp;
var i=0;
var count=0;
for(i=0;i<String1.length;i++){
String2 = new String(parseFloat(String1.charAt(i)));
if(String1.charAt(i)==".")
count++;
if((String2.length!=1&&String1.charAt(i)!='.')||count>1){
alert("您輸入了一個非法值 " + label);
return false;
}
}
return true;
}
function CheckParam(Param1,Param2,Param3,Param4){
var Form = document.forms[0].form.options[document.forms[0].form.selectedIndex].text;
var valid1 = 0,valid2 = 0,valid3 = 0,valid4 = 0;
var counter = 0;
if(Form=="Round"||Form=="Hexagonal"||Form=="Octagonal"){
if(Param1==""||Param3==""||Param4 == ""){
alert("必須填寫RRR和LLL的值!");
return false;
}
valid1 = CheckNum(Param1,"AA");
valid3 = CheckNum(Param3,"BB");
valid4 = CheckNum(Param4,"件數");
if(valid1!=true||valid3!=true||valid4!=true)
return false;
}
return true;
}
function CalculateWeight(){
var Param = new Array(5);
var Units = new Array(4);
var Convert;
var FormType;
var Result;
var Good;
Param[0] = document.forms[0].param1.value;
Param[1] = document.forms[0].param2.value;
Param[2] = document.forms[0].param3.value;
Param[3] = document.forms[0].param4.value;
Good = CheckParam(Param[0],Param[1],Param[2],Param[3]);
if(!Good)
return;
Units[0] = document.forms[0].units1.options[document.forms[0].units1.selectedIndex].text;
Units[1] = document.forms[0].units2.options[document.forms[0].units2.selectedIndex].text;;
Units[2] = document.forms[0].units3.options[document.forms[0].units3.selectedIndex].text;;
Param[0] = UnitConvertI(Param[0],Units[0]);
Param[1] = UnitConvertI(Param[1],Units[1]);
Param[2] = UnitConvertF(Param[2],Units[2]);
FormType = document.forms[0].form.options[document.forms[0].form.selectedIndex].text;
if(document.forms[0].product.selectedIndex>0)
Convert = Factor[document.forms[0].product.selectedIndex-1];
else
Convert = 1;
document.forms[0].result.rsize = "4";
if(FormType=="Round"){
Result = new String(2.6729 * Param[0] * Param[0] * Convert * Param[2] * Param[3]);
document.forms[0].result.value = Result.substring(0,Result.indexOf(".")+RoundOff);
}
}
function ClearFields(){
document.forms[0].param1.value = "";
document.forms[0].param2.value = "";
document.forms[0].param3.value = "";
document.forms[0].param4.value = "1";
document.forms[0].result.value = "";
}
function ChangeLabel(){
var formType;
formType = document.forms[0].form.options[document.forms[0].form.selectedIndex].text;
if(formType=="Round"){
document.forms[0].lbl1.value = "AA";
document.forms[0].lbl2.value = "";
document.forms[0].lbl3.value = "AA";
}
}
ChangeLabel();
ClearFields();
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<table align="center">
<tbody>
<form name="form1" method="POST" onsubmit="CalculateWeight(); return false;">
<tr>
<td> <select name="product">
<option>default</option></select></td></tr>
<tr><td></td>
<td> <select name="form" onchange="ChangeLabel();ClearFields();">
<option value="https://img.uj5u.com/2020/09/19/101767190323571.jpg">Round</option>
</select>
</td></tr>
<tr><td></td>
<td> <input name="param4" size="6" maxlength="10" value="https://bbs.csdn.net/topics/1" type="text">
</td></tr>
<tr> <td>
<input name="lbl1" size="12" onfocus="if(navigator.appName == 'Netscape'&& parseInt(navigator.appVersion) == 3); else document.forms[0].param1.focus(); " onblur="ChangeLabel();" value="https://bbs.csdn.net/topics/RRR" type="text">
</td> <td><input name="param1" size="6" maxlength="10" type="text">
<select name="units1"><option >ccc
</option><option>ccc
</option><option>aaa
</option><option>bbb
</option><option selected="selected">aaa
</option></select>
</td></tr>
<tr><td>
</td> <td> <input name="param2" size="6" maxlength="10" type="text">
<select name="units2">
<option >ddd
</option><option>aaa
</option><option>bbb
</option><option>ccc
</option><option selected="selected">ccc
</option></select>
</td></tr>
<tr><td>
<input name="lbl3" size="12" onfocus="if(navigator.appName == 'Netscape'&& parseInt(navigator.appVersion) == 3); else document.forms[0].param3.focus(); " onblur="ChangeLabel();" value="https://bbs.csdn.net/topics/LLL" type="text">
</td> <td> <input name="param3" size="6" maxlength="10" type="text">
<select name="units3">
<option >aaa
</option><option>CCC
</option><option>BBB
</option><option>ddd
</option><option selected="selected">ccc
</option></select>
</td></tr>
<tr><td height="15"></td></tr>
<tr> <td >
<input name="Submit" value="https://bbs.csdn.net/topics/計算" style="margin-left:1cm" type="submit">
</td> </tr>
<tr><td height="15"></td></tr>
<tr>
<td colspan="2"><b><font face="verdana" size="2" color="#FF0000">結果</font></b></td></tr>
<tr><td colspan="2"><font size="2" face="verdana" color="darkblue">
<b style="margin-left:.5cm">
<input maxlength="8" name="result" size="10" onfocus="if(navigator.appName == 'Netscape'&& parseInt(navigator.appVersion) == 3); else document.forms[0].Submit.focus(); " onblur="ChangeLabel();" type="text">
Lb</b></font></td></tr>
</tbody></table>
</form>
uj5u.com熱心網友回復:
跳轉的原因是js有錯誤,onsubmit事件中CalculateWeight()函式出錯,之后的return false;沒有執行,也就沒有阻止表單提交。
uj5u.com熱心網友回復:
這個在本地電腦測沒問題,傳到服務器就不正常。具體怎么改呢? 我不會哦
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/78432.html
標籤:JavaScript
上一篇:跪求,怎么制作如圖所示的用戶注冊界面啊,剛學的web只會簡單的一些表格和div標簽 怎么做?
下一篇:td中的div垂直居中
