为什么我的 Javascript 函数只能运行一段时间?
我的沙箱在这里:http://9.latest.truxmap.appspot.com/
首先单击地图上的标记(如果页面加载时没有标记,请选中导航小部件中的“食品卡车即将开业”框)。接下来转到“评论”选项卡。
在 GWT 中,每次打开标记时,我都会调用 javascript 函数 resizeReviewTab(),该函数可以纠正由于状态和审阅选项卡中的内容是动态的而出现的样式问题。如果 Javascript 有效,那么您将看到“评论”选项卡中文本区域正上方漂浮着星星,而不是单选按钮。否则,您将看到普通的单选按钮。
我不知道当标记不能正确打开时会发生什么。它怎么可能一次起作用,然后不再起作用,然后在几个不同的标记之后再次起作用?下面是这个函数:
function resizeReviewTab(){
$('#content').text("");
$('.statusWindowB').css('height', $('.statusWindowA').css('height'));
$('.name-sliding').focus(function() {
$('.name-label-sliding').animate({ marginLeft: "133px" }, "fast");
if($(this).val() == "name")
$(this).val() == "";
}).blur(function() {
if($(this).val() == "") {
$(this).val() == "name";
$('.name-label-sliding').animate({ marginLeft: "12px" }, "fast");
}
});
$('.content-sliding').focus(function() {
$('.content-label-sliding').fadeOut("slow");
});
starify();
}
starify() 是 jQuery 插件 jquery.stars 的 javascript,做了一些修改,如下所示: http://9.latest.truxmap.appspot.com/lib/jquery. rating.js
我需要调用这个函数,因为如果我只是在在 html 文档的开头,通过单击地图创建的任何信息窗口都不会将其单选按钮更改为星形。
这个问题有点麻烦,期待您的回复。谢谢!
My sandbox is here: http://9.latest.truxmap.appspot.com/
First click a marker on the map (if there are none when the page loads, check the 'food trucks opening soon' box in the navigation widget). Next go to the 'Reviews' tab.
In GWT, everytime I open a marker I'm calling the javascript function resizeReviewTab() which corrects styling issue that arise given the fact that the content in the status and review tabs are dynamic. If the Javascript worked, then you will see STARS rather than radio buttons floating right above the text area in the 'Reviews' tab. Otherwise, you'll see plain radio buttons.
I cant figure out what happens when the marker DOESNT open up properly. How could it work once, then not again, then work again after a few different markers? Heres the function thats called:
function resizeReviewTab(){
$('#content').text("");
$('.statusWindowB').css('height', $('.statusWindowA').css('height'));
$('.name-sliding').focus(function() {
$('.name-label-sliding').animate({ marginLeft: "133px" }, "fast");
if($(this).val() == "name")
$(this).val() == "";
}).blur(function() {
if($(this).val() == "") {
$(this).val() == "name";
$('.name-label-sliding').animate({ marginLeft: "12px" }, "fast");
}
});
$('.content-sliding').focus(function() {
$('.content-label-sliding').fadeOut("slow");
});
starify();
}
starify() is the javascript for the jQuery plugin jquery.stars with a few modifications, visible here: http://9.latest.truxmap.appspot.com/lib/jquery.rating.js
I need to call this function because if I merely load it at the beginning of the html document, none of the info windows created by clicking the map will ever have their radio buttons changed into stars.
This is quite bothersome, I'm looking forward to your replies. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这些位肯定坏了
我
想你的意思
是
These bits are definitely broken
And
I think you meant
And
@amurra 和 @meouw 给出的两个答案是有效的,并且可能会在将来引起问题。然而,OP中提出的问题的答案是,每次活动单元格发生变化时,GWT都会调用
SelectionChangedHandler
两次——一次是在取消选择一个单元格时,一次是在另一个单元格被选中时。重新选择。这导致 javascript 函数被连续调用两次,从而导致令人讨厌的行为。非常感谢您在此线程中的帮助!The two answers given by @amurra and @meouw were valid and could have caused issues in the future. However, the answer to the question asked the in OP is that GWT calls the
SelectionChangedHandler
TWICE, every time the active cell is changed -- once when a cell is de-selected, and once when another cell is re-selected. This was causing the javascript function to be called twice, back-to-back, which was leading to nasty behavior. Thanks a lot for the help in this thread!如果函数被多次调用,您可能需要在绑定之前取消绑定事件。这将有助于防止多次绑定,从而导致奇怪且不一致的结果。
}
You might want to unbind your events before binding if a function gets called multiple times. This will help prevent multiple binds, which can cause weird and inconsistent results.
}