简体   繁体   English

多次加载时,jquery cluetip中断

[英]jquery cluetip breaks when loaded more than once

I am using the jQuery cluetip plugin in a portal environment where there can be more than one instance of a portlet on a portal page. 我在门户网站环境中使用jQuery cluetip插件,其中门户网站页面上可能有多个portlet实例。 Each portlet is its own app, so it really knows nothing about the other portlets. 每个portlet都是其自己的应用程序,因此对于其他portlet确实一无所知。 Each portlet needs to use the cluetip plugin, so it is loading it when it needs it. 每个portlet需要使用cluetip插件,因此需要时将其加载。 The problem is that, when the cluetip script is loaded more than once, it generates the following error: 问题是,当cluetip脚本被多次加载时,它会产生以下错误:

$cluetip is undefined

I know one possible solution is to check whether the plugin is already loaded or not, but every check I have tried fails. 我知道一种可能的解决方案是检查插件是否已加载,但是我尝试过的每项检查均失败。 I have tried: 我努力了:

if(jQuery.cluetip), if(jQuery().cluetip), if(jQuery.fn.cluetip), if(jQuery().fn.cluetip)

and none of them work. 他们都不起作用。 They all return undefined. 它们都返回未定义。

How can I check whether the plugin is already loaded or not? 如何检查插件是否已加载? Or, is there another solution that I can implement? 或者,还有其他我可以实现的解决方案吗?

Are you utilizing cluetip inside a document ready function? 您是否在文档准备功能中利用cluetip?

$(function() {
  $('a.tips').cluetip();
});

It doesn't look like you're using cluetip properly based on the code you posted above. 根据上面发布的代码,您似乎没有正确使用cluetip。 You don't really need to check if the plug-in is loaded. 您实际上不需要检查插件是否已加载。 If you have the script in your header: 如果标题中包含脚本:

<script src="jquery.js" type="text/javascript"></script>
<script src="jquery.cluetip.js" type="text/javascript"></script>

then you just need to select what you want to have a tip on ('a.tips') in my example above, and it should just work. 那么您只需在上面的示例中选择要在其上添加提示的内容('a.tips'),它就可以正常工作。

If you post your Javascript and HTML, I can provide you a better answer. 如果您发布Javascript和HTML,我可以为您提供更好的答案。

Looking at the source from the cuetip site: 从cuetip网站查看源代码:

<script type="text/javascript">
$(document).ready(function() {
  $('a.tips').cluetip();

  $('#houdini').cluetip({
    splitTitle: '|', // use the invoking element's title attribute to populate the clueTip...
                     // ...and split the contents into separate divs where there is a "|"
    showTitle: false // hide the clueTip's heading
  });
});
</script>
<link rel="stylesheet" href="jquery.cluetip.css" type="text/css" />

Things to notice is that the first thing loaded is jQuery.js, followed by cuetip. 需要注意的是,首先加载的是jQuery.js,其次是cuetip。

Make sure that your html looks the same, and make sure that the cuetip AND jQuery are loading fine. 确保您的html外观相同,并确保提示提示和jQuery可以正常加载。

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

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