【发布时间】:2013-11-27 00:23:46
【问题描述】:
我正在使用 jQuery 工具提示动态创建行(可以是 10 行/更多行)
工具提示显示正常,但关闭不正常。
错误如下,
Error: cannot call methods on tooltip prior to initialization; attempted to call method 'close'
throw new Error( msg );
while(m < 10){
.......................................
.......................................
if(data =="EXIST")
{
display_tp_tooltip(m);
$("#tp_no"+m).val("");
}
else
{
display_tp_tooltip_close(m);
}
}
function display_tp_tooltip(m)
{
$("#tp_no"+m).tooltip();
$("#tp_no"+m).tooltip({
open: function (e, o) {
o.tooltip.animate({ top: o.tooltip.position().top + 10 }, "fast" );
$(o.tooltip).mouseover(function (e) {
$("#tp_no"+m).tooltip('close');
});
$(o.tooltip).mouseout(function (e) {});
},
position: {
my: "center bottom-20",
at: "center top",
using: function( position, feedback ) {
$( this ).css( position );
$( "<div>" )
.addClass( "arrow" )
.addClass( feedback.vertical )
.addClass( feedback.horizontal )
.append($('<style>.ui-tooltip,.arrow:after { background:red; }</style>'))
.appendTo( this );
}
},
content: function() { return cellTpNoTooltipContent()},
close: function (e, o) {},
show: {
duration: 800
}
});
$("#tp_no"+m).tooltip('open');
setTimeout(function () {
$(this).tooltip('close'); //close the tooltip
}, 3000);
}
function cellTpNoTooltipContent()
{
var rval = "T.P No. is exist";
return rval;
}
function display_tp_tooltip_close(m)
{
$("#tp_no"+m).tooltip("close");
}
我该如何解决?请帮帮我。
【问题讨论】:
-
您的错误已经解释过了,您在 else 语句中立即调用 close 方法,我们无能为力,因为我们不知道 EXIT 来自哪里以及您的代码逻辑
-
存在来自输入验证。 Exist 使用 ajax 从数据库中正确检查,当 Exist 没有出现时,我会通过 alert 进行检查,它工作正常。但是当调用 display_tp_tooltip_close 函数并关闭工具提示时,它会在上面显示问题。
-
好的,有道理。然后,查看this SO question 并查看 john 发布的未接受的答案。它可能会有所帮助。
标签: jquery twitter-bootstrap jquery-ui compiler-errors dynamic-data