简体   繁体   English

Javascript参考错误功能

[英]Javascript reference error to function

I want to call a Javascript function every time a checkbox changes its value. 每次复选框更改其值时,我都想调用Javascript函数。 I do the same for inputs of the select type and there it works just fine. 我对选择类型的输入做同样的事情,它工作得很好。 Both inputs are in one table. 两个输入都在一个表中。 This is one element that calls the first function: 这是调用第一个函数的一个元素:

<td>
    <select name="minuteEnd" id="minuteEnd" onChange="calculateWorkTime()">'.$dropDown_minuteEnd.'
    </select>
</td>

And the part which calls the second function 以及调用第二个函数的部分

<td>
    <input type="checkbox" name="deleteShift" id="deleteShift" onChange="updateSubmitButton()" /><br />
    <input type="checkbox" name="deleteShiftConfirm" id="deleteShiftConfirm" onChange="updateSubmitButton()" />.
</td>

Then I define both functions in separate script tags, but I also tried to define them in one, that did not solve the problem. 然后我在单独的脚本标签中定义了这两个函数,但我也尝试将它们定义在一个中,但没有解决问题。 Because I do not always need both of them I call a PHP-function for each to be written. 因为我并不总是需要它们,所以我为每个函数调用一个PHP函数。 These PHP functions are 这些PHP函数是

drawScriptCalculateWorkTime();
drawScriptUpdateSubmitbutton();

the actual Javascript code is this: 实际的Javascript代码是这样的:

function drawScriptCalculateWorkTime()
{
    echo'
    <script>
        function calculateWorkTime()
        {
            //I work (My name can be found)
        }
    </script>
    ';
}

function drawScriptUpdateSubmitbutton()
{
    echo'
    <script>
        function updateSubmitButton()
        {
            //I do not work. I get the error: ReferenceError: updateSubmitButton is not defined
            //This is my code
            var delete = document.getElementById("deleteShift").checked;
            var deleteConfirm = document.getElementById("deleteShiftConfirm").checked;

            if(delete && deleteConfirm)
            {
                document.getElementById("submitButton").disabled = false;
            }
        }
    </script>
    ';
}

My Browser-console always tells me 我的浏览器控制台总是告诉我

ReferenceError: updateSubmitButton is not defined,

but I checked the name about 20 times. 但我检查了这个名字大约20次。 Further, it always tells me on window load this: 此外,它总是告诉我窗口加载:

SyntaxError: missing variable name

This refers to the first line of Code of the second javascript. 这是指第二个javascript的第一行代码。

I already checked google and even found a quite similar question here ( Javascript Uncaught Reference error Function is not defined ) but that solution did not work for me. 我已经检查了谷歌,甚至在这里发现了一个非常相似的问题( Javascript Uncaught Reference错误功能未定义 )但该解决方案对我不起作用。

If I did not provide all information needed I will provide them right away. 如果我没有提供所需的所有信息,我会立即提供。

John 约翰

在javascript中, delete是保留字,不能用于变量名。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM