简体   繁体   English

Javascript在localhost上运行良好,在服务器上不运行

[英]Javascript works great on localhost, doesn't work on server

I am perplexed about why my script works on my laptop but doesn't work when I put it up on the server: 我对为什么我的脚本可以在笔记本电脑上运行但为什么无法将其放在服务器上时感到困惑:

<HTML>
<HEAD>
    <TITLE>Cubic Feet</TITLE>
    <SCRIPT LANGUAGE="text/javascript">


    function Calculate()
    {
        var qty1 = document.getElementById('q1').value;
        var len1 = document.getElementById('l1').value;
        var width1 = document.getElementById('w1').value;
        var height1 = document.getElementById('h1').value;
        var cube1 = (qty1*(len1*width1*height1))/1728;
        var ss1 = cube1/53.3;

        var qty2 = document.getElementById('q2').value;

        if (qty2 =="") {
            qty2=0
            cube2=0
            ss2=0;
        }

        var len2 = document.getElementById('l2').value;
        var width2 = document.getElementById('w2').value;
        var height2 = document.getElementById('h2').value;
        var cube2 = (qty2*(len2*width2*height2))/1728;
        var ss2 = cube2/53.3;

        var qty3 = document.getElementById('q3').value;

        if (qty3=="") {
            qty3=0;
            cube3=0;
            ss3=0;
        }

        var len3 = document.getElementById('l3').value;
        var width3 = document.getElementById('w3').value;
        var height3 = document.getElementById('h3').value;
        var cube3 = (qty3*(len3*width3*height3))/1728;
        var ss3 = cube3/53.3;  


        var totcube = cube1 + cube2 + cube3;
        var totskid = ss1 + ss2+ss3;
        var tq = parseInt(qty1) + parseInt(qty2)+parseInt(qty3);
        var trlft = totskid * 2;

        var form = document.forms[0];

        form.cuft1.value = cube1.toFixed(2);
        form.sk1.value = ss1.toFixed(1);
        form.cuft2.value = cube2.toFixed(2);
        form.sk2.value = ss2.toFixed(1);
        form.cuft3.value = cube4.toFixed(2);
        form.sk3.value = ss4.toFixed(1);


        form.totalcuft.value = totcube.toFixed(2); 
        form.sktotal.value = totskid.toFixed(1);
        form.totalqty.value = tq.toFixed(1);
        form.feet.value = trlft.toFixed(1);

    }

    function ClearForm(form)
    {
        form.q1.value = "";
        form.l1.value = "";
        form.w1.value = "";
        form.h1.value = "";
        form.cuft1.value = "";
        form.q2.value = "";
        form.l2.value = "";
        form.w2.value = "";
        form.h2.value = "";
        form.cuft2.value = "";
        form.q3.value = "";
        form.l3.value = "";
        form.w3.value = "";
        form.h3.value = "";
        form.cuft3.value = "";
        form.totalcuft.value = "";
        form.sktotal.value = "";
        form.totalqty.value = "";
        form.feet.value = "";
    }

    // end of JavaScript functions -->
    </SCRIPT>
</HEAD>

<BODY>

<FORM NAME="Calculator" METHOD="post">

Enter the quantity (number of pieces, skids, boxes, whatever) and their dimensions (length, width, height) in INCHES, then click Calculate.

<P><INPUT TYPE="button" VALUE="Calculate" name="AddButton"  onClick="Calculate(this.form.q1.value, this.form.h1.value, this.form.w1.value, this.form.l1.value, this.form)">
<INPUT TYPE="button" VALUE="Clear" name="ClearButton" onClick="ClearForm(this.form)">

<p>
<table>
    <tr>
        <td> Container 1 Qty <input type="TEXT" id="q1" value="" size="5"></td>
        <td> Length <input type="TEXT" id="l1" value="" size ="5"></td>
        <td> Width <input type="TEXT" id="w1" value="" size = "5"></td>
        <td> Height <input type="TEXT" id="h1" value="" size = "5"></td>
        <td> Cu.Ft. <input type="TEXT" id="cuft1" value="" size = "5"></td> 
        <td> Skid spots <input type="TEXT" id="sk1" value="" size ="5"></td>
    </tr>
    <tr>
        <td> Container 2 Qty <input type="TEXT" id="q2" value="" size="5"></td>
        <td> Length <input type="TEXT" id="l2" value="" size="5"></td>
        <td> Width <input type="TEXT" id="w2" value="" size="5"></td>
        <td> Height <input type="TEXT" id="h2" value="" size="5"></td>
        <td> Cu.Ft. <input type="TEXT" id="cuft2" value="" size="5"></td>
        <td> Skid spots <input type="TEXT" id="sk2" value="" size="5"></td>
    </tr>
    <tr>
        <td> Container 3 Qty <input type="TEXT" id="q3" value="" size="5"></td>
        <td> Length <input type="TEXT" id="l3" value="" size="5"></td>
        <td> Width <input type="TEXT" id="w3" value="" size="5"></td>
        <td> Height <input type="TEXT" id="h3" value="" size="5"></td>
        <td> Cu.Ft. <input type="TEXT" id="cuft3" value="" size="5"></td>
        <td> Skid spots <input type="TEXT" id="sk3" value="" size="5"></td>
    </tr>
    <tr>

        <td>Totals:</td>
    </tr>
    <tr>
        <td> Total Qty <input type="TEXT" id="totalqty" value="" size="5"></td>
        <td> Cu.Ft. <input type="TEXT" id="totalcuft" value="" size="5"></td>
        <td> Skid spots <input type="TEXT" id="sktotal" value="" size="5"></td>
        <td> Linear Feet <input type="TEXT" id="feet" value="" size="5"></td>
    </tr>
</table>
</FORM>
</BODY>
</HTML>

What could be causing it to not work on the server? 是什么导致它在服务器上不起作用?

There's no error messages. 没有错误消息。 Answers aren't being produced when I click calculate after I upload it onto the server. 将计算结果上传到服务器后,单击“计算”并没有产生答案。 Works perfectly locally. 在本地完美运行。

Thanks for having a look. 感谢您的浏览。

Replace cube4 with cube3 , ss4 with ss3 , text/javascript with javascript and put <!-- after <SCRIPT> . cube4替换为cube3 ,将ss4替换为ss3 ,将text/javascript替换为javascript并在<SCRIPT>之后放置<!--

Here is what you should get after these replacements: 这些替换后,您应该获得以下内容:

<HTML>
<HEAD>
<TITLE>Cubic Feet</TITLE>
<SCRIPT LANGUAGE="javascript">
<!--
function Calculate()
{
var qty1 = document.getElementById('q1').value;
var len1 = document.getElementById('l1').value;
var width1 = document.getElementById('w1').value;
var height1 = document.getElementById('h1').value;
var cube1 = (qty1*(len1*width1*height1))/1728;
var ss1 = cube1/53.3;

var qty2 = document.getElementById('q2').value;

if (qty2 =="") {
   qty2=0
   cube2=0
   ss2=0;
}

var len2 = document.getElementById('l2').value;
var width2 = document.getElementById('w2').value;
var height2 = document.getElementById('h2').value;
var cube2 = (qty2*(len2*width2*height2))/1728;
var ss2 = cube2/53.3;

var qty3 = document.getElementById('q3').value;

if (qty3=="") {
   qty3=0;
   cube3=0;
   ss3=0;
}

var len3 = document.getElementById('l3').value;
var width3 = document.getElementById('w3').value;
var height3 = document.getElementById('h3').value;
var cube3 = (qty3*(len3*width3*height3))/1728;
var ss3 = cube3/53.3;


var totcube = cube1 + cube2 + cube3;
var totskid = ss1 + ss2+ss3;
var tq = parseInt(qty1) + parseInt(qty2)+parseInt(qty3);
var trlft = totskid * 2;

var form = document.forms[0];

form.cuft1.value = cube1.toFixed(2);
form.sk1.value = ss1.toFixed(1);
form.cuft2.value = cube2.toFixed(2);
form.sk2.value = ss2.toFixed(1);
form.cuft3.value = cube3.toFixed(2);
form.sk3.value = ss3.toFixed(1);


form.totalcuft.value = totcube.toFixed(2);
form.sktotal.value = totskid.toFixed(1);
form.totalqty.value = tq.toFixed(1);
form.feet.value = trlft.toFixed(1);

}

function ClearForm(form)
{
form.q1.value = "";
form.l1.value = "";
form.w1.value = "";
form.h1.value = "";
form.cuft1.value = "";
form.q2.value = "";
form.l2.value = "";
form.w2.value = "";
form.h2.value = "";
form.cuft2.value = "";
form.q3.value = "";
form.l3.value = "";
form.w3.value = "";
form.h3.value = "";
form.cuft3.value = "";
form.totalcuft.value = "";
form.sktotal.value = "";
form.totalqty.value = "";
form.feet.value = "";
}

// end of JavaScript functions -->
</SCRIPT>
</HEAD>

<BODY>

<FORM NAME="Calculator" METHOD="post">

Enter the quantity (number of pieces, skids, boxes, whatever) and their dimensions (length, width, height) in INCHES, then click Calculate.

<P><INPUT TYPE="button" VALUE="Calculate" name="AddButton"  onClick="Calculate(this.form.q1.value, this.form.h1.value, this.form.w1.value, this.form.l1.value, this.form)">
<INPUT TYPE="button" VALUE="Clear" name="ClearButton" onClick="ClearForm(this.form)">

<p>
<table>
<tr>
<td> Container 1 Qty <input type="TEXT" id="q1" value="" size="5"></td>
<td> Length <input type="TEXT" id="l1" value="" size ="5"></td>
<td> Width <input type="TEXT" id="w1" value="" size = "5"></td>
<td> Height <input type="TEXT" id="h1" value="" size = "5"></td>
<td> Cu.Ft. <input type="TEXT" id="cuft1" value="" size = "5"></td>
<td> Skid spots <input type="TEXT" id="sk1" value="" size ="5"></td>
</tr>
<tr>
<td> Container 2 Qty <input type="TEXT" id="q2" value="" size="5"></td>
<td> Length <input type="TEXT" id="l2" value="" size="5"></td>
<td> Width <input type="TEXT" id="w2" value="" size="5"></td>
<td> Height <input type="TEXT" id="h2" value="" size="5"></td>
<td> Cu.Ft. <input type="TEXT" id="cuft2" value="" size="5"></td>
<td> Skid spots <input type="TEXT" id="sk2" value="" size="5"></td>
</tr>
<tr>
<td> Container 3 Qty <input type="TEXT" id="q3" value="" size="5"></td>
<td> Length <input type="TEXT" id="l3" value="" size="5"></td>
<td> Width <input type="TEXT" id="w3" value="" size="5"></td>
<td> Height <input type="TEXT" id="h3" value="" size="5"></td>
<td> Cu.Ft. <input type="TEXT" id="cuft3" value="" size="5"></td>
<td> Skid spots <input type="TEXT" id="sk3" value="" size="5"></td>
</tr>
<tr>

<td>Totals:</td>
</tr>
<tr>
<td> Total Qty <input type="TEXT" id="totalqty" value="" size="5"></td>
<td> Cu.Ft. <input type="TEXT" id="totalcuft" value="" size="5"></td>
<td> Skid spots <input type="TEXT" id="sktotal" value="" size="5"></td>
<td> Linear Feet <input type="TEXT" id="feet" value="" size="5"></td>
</tr>
</table>
</FORM>
</BODY>
</HTML>

This works fine for me in Firefox. 这在Firefox中对我来说效果很好。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 灶神星 | Laravel Ajax 在服务器上不工作,但在本地主机上工作 - VestaCP | Laravel Ajax doesn't work on server but works in localhost 为什么 JavaScript 在 localhost 上不起作用,但在我的机器上运行得很好? - Why JavaScript doesn't work on localhost but works perfectly on my machine? jQuery脚本仅需单击即可很好地工作,不适用于keydown事件 - jQuery script works great with a click, doesn't work with keydown event 本地主机上的Javascript不起作用 - Javascript on localhost doesn't work AJAX 适用于本地主机,但不适用于实时服务器 - AJAX works on localhost, but doesn't on live server 有些Javascript可在Localhost上运行,有些则不能-所有Java均可在远程服务器上运行? - Some Javascript Works on Localhost, Some Doesn't - All Works on Remote Server? Javascript在本地运行良好,但不在我的服务器上 - Javascript works great locally, but not on my server Angular JS $ http.get()不适用于我的服务器,它可与localhost一起使用 - Angular JS $http.get() doesn't work with my server, it works with localhost tho Javascript问题,使用localhost可以正常运行网站,使用computername不能正常工作 - Javascript issue, site works fine using localhost, doesn't work using computername jQuery UI自动完成功能不适用于已部署的应用程序,但适用于localhost - jQuery UI autocomplete doesn't work on deployed application but works on localhost
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM