MD.*_*lim 11 jquery compiler-errors jquery-ui dynamic-data twitter-bootstrap
我正在使用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");
}
Run Code Online (Sandbox Code Playgroud)
我怎么解决呢?请帮我.
您需要防止 jQuery UI 库覆盖jQuery.fn.tooltip.
所以在加载 jQuery UI 库之前缓存这个值,然后再恢复它:
<script>
let _tooltip = jQuery.fn.tooltip; // <--- Cache this
</script>
<script src="/path/to/jquery-ui.min.js"></script> <!-- load jQuery UI -->
<script>
jQuery.fn.tooltip = _tooltip; // <--- Then restore it here
</script>
Run Code Online (Sandbox Code Playgroud)
我总是在调用 close 方法等之前检查元素是否存在。
if ($(myelem).length > -1) {
// do something
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18332 次 |
| 最近记录: |