[英]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.