zk服务器端获取鼠标点击位置
程序员文章站
2022-07-13 21:46:48
...
index.zul
- <? xml version = "1.0" ?>
- < window xmlns:w = "client" xmlns:n = "native" xmlns = "http://www.zkoss.org/2005/zul"
- xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation = "http://www.zkoss.org/2005/zul http://www.zkoss.org/2005/zul/zul.xsd"
- id = "indexWin" border = "normal" title = "鼠标点击数据演示" width = "600px" height = "500px"
- apply = "cn.zkoss.zk4love.web.controller.MouseClickController" >
- < div style = "float:left;" >
- < button label = "I'am here(client)"
- w:onClick = "zk.log('纯js:x='+zk.clickPointer[0]+',y='+zk.clickPointer[1])" />
- < n:br />
- < n:br />
- < button label = "I'am here(client)"
- w:onClick = "zk.log('纯js:x='+zk.clickPointer[0]+',y='+zk.clickPointer[1])" />
- < n:br />
- < n:br />
- < button label = "I'am here(client)"
- w:onClick = "zk.log('纯js:x='+zk.clickPointer[0]+',y='+zk.clickPointer[1])" />
- < n:br />
- < n:br />
- </ div >
- < script type = "text/javascript" >
- function sendPointer(){
- zAu.send(new zk.Event(zk.Widget.$('$indexWin'),'onShowPointer',zk.clickPointer[0]+','+zk.clickPointer[1]));
- return true;
- }
- </ script >
- < div style = "float:right;" >
- < button label = "I'am here(Server)" w:onClick = "sendPointer();" />
- < n:br />
- < n:br />
- < button label = "I'am here(Server)" w:onClick = "sendPointer();" />
- < n:br />
- < n:br />
- < button label = "I'am here(Server)" w:onClick = "sendPointer();" />
- < n:br />
- < n:br />
- </ div >
- </ window >
后台代码
- package cn.zkoss.zk4love.web.controller;
- import org.zkoss.zk.ui.Component;
- import org.zkoss.zk.ui.event.Event;
- import org.zkoss.zk.ui.util.Clients;
- import org.zkoss.zk.ui.util.GenericForwardComposer;
- public class MouseClickController extends GenericForwardComposer {
- private static final long serialVersionUID = 2734553685458769226L;
- public void doAfterCompose(Component comp) throws Exception {
- super .doAfterCompose(comp);
- }
- public void onShowPointer(Event e){
- Clients.log("后台获取数据=" +e.getData());
- }
- }
本功能已添加到zk4love项目
svn下载地址: http://zk4love.googlecode.com/svn/trunk/zkportal
本示例在线演示 http://zkfiddle.org/sample/39o3m78/3-The-last-position-that-the-mouse-was-clicked
进入后点击右上角的run
-------------------
zk中国的开源项目zk4love
关于项目
ZK@China 群25891428、88280491专注于zk开发及研究。
本项目主要由群内成员及 论坛
提问sun4love收集整理并解决汇集而成!
以帮助zk用户快速理解掌握zk技术细节,提高同学学习成绩和公司开发人员的开发效率!
本项目完全来源于中国开发者所关注的问题,更贴切中国开发者,与zkoss.org官网的demo不同,zk4love更加详细具体遵从MVC的开发模式!
下载演示