我正在使用 Gquery 并发现一些难以使用 live() 方法的东西。就我而言,当您想为“未来”元素定义一些行为时,它非常有用。例如,我想在单击某个按钮后将背景颜色更改为我创建的任何水平面板。示例代码附在下面。
RootPanel.get(); //before invoking live method, recommended in gwt forum
GQuery hPanel = mySelectors.getHorizontalPanel();
hPanel.live(Event.ONCLICK, new Function () {
public boolean f (Event e) {
int red = 100;
int green = 100;
int blue = 100;
while (red < 250) {
while (green < 250) {
while (blue < 250) {
String bgColor = "backgroundColor: 'rgb(" + red + "," + green + "," + blue + ")'";
$(e).animate(bgColor,8);
blue+=10;
}
green+=10;
}
red+=10;
}
return false;
}
});
HorizontalPanel horizontalPanel = new HorizontalPanel();
horizontalPanel.setHeight("40px");
horizontalPanel.setWidth("40px");
horizontalPanel.setStyleName("horizontal-panel");
final HorizontalPanel newPanel = new HorizontalPanel();
newPanel.add(horizontalPanel);
RootPanel.get("horizontalPanels").add(newPanel);
出于某种原因,当我单击面板时不会调用任何事件。选择器的声明方式如下:
@Selector(".horizontal-panel")
GQuery getHorizontalPanel();
任何帮助或对此问题的了解将不胜感激,
提前致谢!