简体   繁体   English

未捕获的ReferenceError:未在onclick上定义

[英]Uncaught ReferenceError: is not defined onclick

On onclick I am getting Uncaught ReferenceError: akkiTooltip is not defined . 在onclick上,我遇到了Uncaught ReferenceError: akkiTooltip is not defined
Check the code that I am using: 检查我使用的代码:

$(document).ready(function () {
    function akkiTooltip() {
        function applyTooltip(element, word) {
            var tooltipText = $('' + element + ' label').data('tooltip');
            var newContent = $('' + element + ' label').html().replace(word, '<span data-tooltip="' + tooltipText + '">' + word + '</span>');
            $('' + element + ' label').removeAttr('data-tooltip');
            return $('' + element + ' label').html(newContent);
        }
        applyTooltip('#question_307', 'Some text');
    }
});

This is from another js file where I am applying onclick: 这来自另一个我在其中应用onclick的js文件:

$(button)
    .text(this.answers[a].title)
    .attr('type', 'button')
    .attr('class', 'btn')
    .attr('onclick', 'quiz._makeSelection(\'answer_' + this.answers[a].id + '\', ' + go + ', ' + this.answers[a].skipToSection + '); akkiTooltip();');

After moving akkiTooltip function outside $(document).ready function, I am getting this error akkiTooltip函数移至$(document).ready函数之外后,出现此错误

Uncaught TypeError: Cannot read property 'replace' of undefined

Move definition of akkitooltip function outside document.ready function. 移动的定义akkitooltip功能之外document.ready功能。 It is not accessible from there. 从那里不能访问它。

Cannot read property 'replace' of undefined

See where you are using .replace 查看您在哪里使用.replace

$('' + element + ' label').html().replace(word, '...');

So, $('' + element + ' label').html() is not what you expect, ie $('' + element + ' label') found no elements so .html() did not return a String 因此, $('' + element + ' label').html()不是您期望的,即$('' + element + ' label')没有找到元素,因此.html()没有返回字符串

Check an element described by the selector #question_307 label exists 检查选择器#question_307 label描述的元素#question_307 label存在


When I tried reproducing this error I actually got null instead of undefined so it might be a different piece of your code 当我尝试重现此错误时,我实际上得到了null而不是undefined因此它可能与您的代码不同

maybe you should check if you set right: 也许您应该检查您是否设置正确:

1.In html and jsp webpage: 1.在html和jsp网页中:

<script src=""></script>

2.In xhtml webpage: 2.在xhtml网页中:

<script src="" />

3.and if your js code(function code) is in the same webpage with the html, you can just use: 3.如果您的js代码(功能代码)与html位于同一网页中,则可以使用:

<script> {your js code} </script>

the default script type is "test/javascript" 默认脚本类型为“ test / javascript”

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

相关问题 未捕获的 ReferenceError:未使用 onclick 定义函数 - Uncaught ReferenceError: function is not defined with onclick 未捕获的ReferenceError:onclick上未定义函数 - Uncaught ReferenceError: function not defined at onclick 未捕获的ReferenceError:未在onclick上定义obj - Uncaught ReferenceError: obj is not defined onclick 未捕获的ReferenceError:在HTMLButtonElement.onclick中未定义函数 - Uncaught ReferenceError: function is not defined at HTMLButtonElement.onclick 未捕获的ReferenceError:未在HTMLButtonElement.onclick上定义toggleFunction - Uncaught ReferenceError: toggleFunction is not defined at HTMLButtonElement.onclick 未捕获到的ReferenceError:在HTMLInputElement.onclick上未定义myFunctionName - Uncaught ReferenceError: myFunctionName is not defined at HTMLInputElement.onclick 未捕获的参考错误:<function> 未在 HTMLInputElement.onclick 中定义 - Uncaught ReferenceError: <function> is not defined at HTMLInputElement.onclick 未捕获的ReferenceError:onclick函数Javascript上未定义变量 - Uncaught ReferenceError: variable is not defined on onclick function Javascript 未捕获的ReferenceError:未在HTMLButtonElement.onclick上定义测试 - Uncaught ReferenceError: testing is not defined at HTMLButtonElement.onclick 未捕获的 ReferenceError:在 HTMLAnchorElement.onclick 中未定义犯罪 - Uncaught ReferenceError: Crime is not defined at HTMLAnchorElement.onclick
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM