Mootools 工具提示未显示 Request.HTML 内容
我在向 Request.HTML 添加提示时遇到一些问题 功能。我有一个 div 每 30 秒刷新一次其内容。 返回的内容有一系列带有类名的div “.liveReader”。
这是我必须启动内容的 JS
window.addEvent('domready', initLiveContent);
function initLiveContent()
{
var tips = new Tips('.liveReader');
(function() { refreshPanel() }).periodical(30000);
refreshPanel();
}
function refreshPanel()
{
var myRequest = new Request.HTML({
url: '/inc/liveFeed.aspx',
update: $('liveContent'),
method: 'get',
onComplete: function() {
tips.attach('.liveReader');
}
});
myRequest.send();
}
所以 HTML 是
<div id="liveContent">
<div id="item1" class="liveReader" title="item 1"><p>Text 1</p></div>
<div id="item2" class="liveReader" title="item 2"><p>Text 2</p></div>
</div>
然而我看到的只是正常的工具提示标题!有什么想法吗?
I'm having some trouble with adding tips to a Request.HTML
function. I have a div which refreshes its content every 30 seconds.
The content returned has a series of divs with the class name
".liveReader".
Here's the JS I have to initiate the content
window.addEvent('domready', initLiveContent);
function initLiveContent()
{
var tips = new Tips('.liveReader');
(function() { refreshPanel() }).periodical(30000);
refreshPanel();
}
function refreshPanel()
{
var myRequest = new Request.HTML({
url: '/inc/liveFeed.aspx',
update: $('liveContent'),
method: 'get',
onComplete: function() {
tips.attach('.liveReader');
}
});
myRequest.send();
}
So the HTML is
<div id="liveContent">
<div id="item1" class="liveReader" title="item 1"><p>Text 1</p></div>
<div id="item2" class="liveReader" title="item 2"><p>Text 2</p></div>
</div>
Yet all I am seeing is the normal tooltip title! any ideas?!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的问题在于变量范围。
您的
onComplete
处理程序使用对tips
的引用,而此变量是initLiveContent
函数的本地变量。因此,onComplete
调用失败。因此,第一个技巧(没有双关语):始终从实际的调试器开始,并将其设置为在所有异常时中断。否则,由于错误(“未定义的变量
tips
”)是从回调中引发的,因此它不会出现在标准控制台中。然后,有两种方法可以修复代码:
使
tips
成为共享变量。例如,您可以在函数中声明它,该函数将作为window.addEvent
调用的第二个参数,然后在initLiveContent
和onComplete< 中引用它/code> 回调。
更多 Mooish :)
使用元素存储动态检索您的
提示
来自更新的容器的实例。即::)
Your problem is with variable scoping.
Your
onComplete
handler uses a reference totips
, while this variable is local to theinitLiveContent
function. Therefore, theonComplete
call fails.So, first tip (no pun intended): always start with an actual debugger, and set it to break on all exceptions. Otherwise, since the error ("undefined variable
tips
") is thrown from within a callback, it won't appear in the standard console.Then, two ways to fix your code:
Make
tips
a shared variable. You might for example declare it in a function that would be the second argument to yourwindow.addEvent
call, and then reference it in bothinitLiveContent
and youronComplete
callback.Much more Mooish :)
Use Element storage to dynamically retrieve your
Tips
instance from your updated container. That is::)