简体   繁体   English

$cluetip 未定义:为什么?

[英]$cluetip is undefined: why?

When I postload cluetip (ie grab it with ajax and then append a script tag to body), I get the following javascript error: $cluetip is undefined.当我发布提示提示(即使用 ajax 和 append 将脚本标记到正文中)时,我收到以下 javascript 错误:$cluetip 未定义。 However, everything still works.但是,一切仍然有效。 Any idea why?知道为什么吗?

The postload script is well-tested and does not break anything else. postload 脚本经过充分测试,不会破坏其他任何内容。 I have confirmed that the scripts are loading in the correct order.我已确认脚本以正确的顺序加载。

I had a similar problem and here is how I finally resolved it (ie, no more $cluetip undefined error msg).我遇到了类似的问题,这就是我最终解决它的方法(即,不再有$cluetip未定义的错误消息)。

First, here is my scenario which may be similar to yours.首先,这是我的情况,可能与您的情况相似。 On the page, I have a在页面上,我有一个

<div id="sel_area"></div>

It is empty and the idea is to employ jquery/ajax to dynamically generate the desired <select><option>...</option>...</select> HTML code to insert into the #sel_area above like so它是空的,想法是使用 jquery/ajax 动态生成所需的<select><option>...</option>...</select> HTML 代码插入到上面的#sel_area ,如下所示

$('#sel_area').html(data);

where data is the generated HTML select tag.其中 data 是生成的 HTML select标签。

However, I think my problem is because I was not retuning the dynamically generated data result in JSON or in XML format and then processing it accordingly.但是,我认为我的问题是因为我没有以 JSON 或 XML 格式重新调整动态生成的数据结果,然后对其进行相应处理。 Instead, I was lazily returning the result as-is as ordinary text/html.相反,我懒洋洋地将结果原样返回为普通文本/html。 When I kept getting the $cluetip is undefined error no matter what I tried, I decided to use alert(data) to see was was being returned.无论我尝试什么,当我不断收到$cluetip is undefined 错误时,我决定使用alert(data)来查看是否正在返回。 Alas, there I saw with my own eyes that data was not just only what I had echoed but it had the entire html page appended to it.唉,我亲眼看到数据不仅是我回显的内容,而且还附加了整个 html 页面。 The solution was then clear to me, Without giving in to returning data in XML or JSON protocol: I made the following minor changes to solve the problem:解决方案对我来说很清楚,不放弃在 XML 或 JSON 协议中返回数据:我做了以下小改动来解决问题:

The change at the remote script that generates the <select> tag.生成<select>标记的远程脚本的更改。 The last last was最后最后一个是

echo "$select_tag";

I changed this to我把它改成了

echo "$select_tag~";

That is, I appended a trailing ~ (tilde) to serve as a separator between my select_tag string output and the HTML page that I now knew would be appended whether I liked it or not.也就是说,我在我的select_tag字符串 output 和我现在知道的 HTML 页面之间添加了一个尾随 ~(波浪号)作为分隔符,无论我喜欢与否。

The change in the jQuery/AJAX method. jQuery/AJAX 方法的变化。

I replaced the line我换了线

$('#sel_area').html(data);

with the following lines:使用以下几行:

data_list = data.split('~');
$('#sel_area').html(data_list[0]);

There you have it.你有它。 That does the trick.这就是诀窍。 The split method enabled me to detach my desired select_tag from data easily because I had wisely inserted ~ (tilde) to serve as my field separator which I knew was neither part of the select_tag result nor the HTML page to be appended by the system. split 方法使我能够轻松地将所需select_tag从数据中分离出来,因为我明智地插入了 ~(波浪号)作为我的字段分隔符,我知道这既不是select_tag结果的一部分,也不是系统要附加的 HTML 页面。 Hope this helps.希望这可以帮助。

Dynamically-loaded scripts are not available immediately.动态加载的脚本无法立即使用。 You have to wait for the script to completely load, which is a problem more complicated than one might imagine.您必须等待脚本完全加载,这是一个比人们想象的更复杂的问题。

I don't know cluetip, and it may be a typo, but $cluetip won't be defined, $.cluetip (note the " . ") should be.我不知道线索提示,它可能是一个错字,但$cluetip不会被定义, $.cluetip (注意“ . ”)应该是。

A quick look at the docs seems to make me think that cluetip is a function that must be called on some element ie $('#somediv').cluetip(...) .快速浏览一下文档似乎让我觉得这个线索提示是一个 function 必须在某些元素上调用,即$('#somediv').cluetip(...) If you want global defaults you have $.cluetip.setup(...) , but either way, it won't define $cluetip , just $.cluetip .如果你想要全局默认值,你有$.cluetip.setup(...) ,但无论哪种方式,它都不会定义$cluetip ,只是$.cluetip

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

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