如何让这个javascript工作 [英] How do I get this javascript to work

查看:80
本文介绍了如何让这个javascript工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在输入数字时动态地将5个文本框的总和加到第6个文本框中。我的脚本不会运行。我做错了什么。



I am trying to dynamically add up the sum of 5 textboxes into a 6 th text box as the numbers are entered. My script won't run. What am I doing wrong.

<script lang="javascript" type="text/javascript">
            function sum() {
                var TextBoxFirstScoreAnc = document.getElementById('<%= TextBoxFirstScoreAnc.ClientID%>').value;
                var TextBoxAncillaryNonPatScore = document.getElementById('<%= TextBoxAncillaryNonPatScore.ClientID%>').value;
                var TextBoxRestroomScoreAnc = document.getElementById('<%= TextBoxRestroomScoreAnc.ClientID%>').value;
                var TextBoxDustingScoreAnc = document.getElementById('<%= TextBoxDustingCommentsAnc.ClientID%>').value;
                var TextBoxFloorScoreAnc = document.getElementById('<%= TextBoxFloorScoreAnc.ClientID%>').value;

            if ((TextBoxFirstScoreAnc !== "") && (TextBoxAncillaryNonPatScore !== "") && (TextBoxRestroomScoreAnc !== "") && (TextBoxDustingScoreAnc !== "") && (TextBoxFloorScoreAnc !== "")) {
                var newValue = GetDecimalValue(TextBoxFirstScoreAnc) + GetDecimalValue(TextBoxAncillaryNonPatScore) + GetDecimalValue(TextBoxRestroomScoreAnc) + GetDecimalValue(TextBoxDustingScoreAnc) + GetDecimalValue(TextBoxFloorScoreAnc);
                document.getElementById('<%= TextBoxTotalScoreAnc.ClientID%>').value = GetDecimalValue(newValue);
            }
        }
        function GetDecimalValue(value) {
            return (value ? parseFloat(value).toFixed(1) : 0.0);
        }
 </script>

推荐答案

好的,让我继续推进F-ES Sitecore对使用调试器的看法。

执行以下代码,然后在浏览器中按 F12 并运行此功能。它将在第一行暂停。

现在使用 F10 进入它,看看代码实际发生了什么。

Okay, let me carry forward what F-ES Sitecore is saying about the using debugger.
Do the following code, and in browser press F12 and run this function. It'll be paused at the very first line.
Now use the F10 to step into in it and see what is actually happening with your code.
<script lang="javascript" type="text/javascript">
            function sum() {
                debugger;
                var TextBoxFirstScoreAnc = document.getElementById('<%= TextBoxFirstScoreAnc.ClientID%>').value;
                var TextBoxAncillaryNonPatScore = document.getElementById('<%= TextBoxAncillaryNonPatScore.ClientID%>').value;
                var TextBoxRestroomScoreAnc = document.getElementById('<%= TextBoxRestroomScoreAnc.ClientID%>').value;
                var TextBoxDustingScoreAnc = document.getElementById('<%= TextBoxDustingCommentsAnc.ClientID%>').value;
                var TextBoxFloorScoreAnc = document.getElementById('<%= TextBoxFloorScoreAnc.ClientID%>').value;

            if ((TextBoxFirstScoreAnc !== "") && (TextBoxAncillaryNonPatScore !== "") && (TextBoxRestroomScoreAnc !== "") && (TextBoxDustingScoreAnc !== "") && (TextBoxFloorScoreAnc !== "")) {
                var newValue = GetDecimalValue(TextBoxFirstScoreAnc) + GetDecimalValue(TextBoxAncillaryNonPatScore) + GetDecimalValue(TextBoxRestroomScoreAnc) + GetDecimalValue(TextBoxDustingScoreAnc) + GetDecimalValue(TextBoxFloorScoreAnc);
                document.getElementById('<%= TextBoxTotalScoreAnc.ClientID%>').value = GetDecimalValue(newValue);
            }
        }
        function GetDecimalValue(value) {
            return (value ? parseFloat(value).toFixed(1) : 0.0);
        }
 </script>





-KR



-KR


这篇关于如何让这个javascript工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆