`

求解???

    博客分类:
  • zk
 
阅读更多

 

<window title="Test of JavaScript Utilities">
   <html onClick='l.value = "onClick "+event.area'
      onUser='l.value ="onUser " +org.zkoss.lang.Objects.toString(event.data)'><![CDATA[
      <a href="javascript:;" onclick="comm.sendClick(this, 'Hi')">onClick with Hi</a>
      <a href="javascript:;" onclick="comm.sendClick(this)">onClick with null</a>
      <a href="javascript:;" onclick="comm.sendUser(this)">onUser with null</a>
      <a href="javascript:;" onclick="comm.sendUser(this, 'One')">onUser with One</a>
      <a href="javascript:;" onclick="comm.sendUser(this, 'One', 'Two')">onUser with [One, Two]</a>
      <a href="javascript:;" onclick="comm.sendEvent(this, 'onUser', 'XYZ')">onUser with XYZ</a>
   ]]></html>
   <separator/>
   <label id="l"/>
</window>

 这段代码是丛ZK帮助文档中COPY下来的,可是测试没有达到我要的结果,望高手帮助解决!!!

 

目的:让Label 显示event.area ,event.data

 

分享到:
评论
3 楼 sun4love 2011-12-03  
官方文档上的内容,是有版本的,据我所知,最新的官方文档是3.5的,都是比较古老的,某些示例代码会有问题,其实你可以用chrome或firebug或ie9的调试工具测试问题所在

我测试时,comm这个对象是空的,所以所有的a标签的onclick执行报错的

label的onClick=null其实是来自html的onClick,因为comm不起作用,所以onUser事件监听
不起作用

在服务器端onClick和onUser会包装成EventHandler的一个对象实例,
由bsh解释执行,onClick和onUser都属于EventHandler,他们的执行先后,
我忘记了,或许按出现顺序,有待考量,你可以查看EventProcessor
确认一下。

最后:不要相信官方文档,因为有些已经过时了,结合实际情选择,

最好经常关注一下,每个版本的new features,这样你可以了解每个版本的不同,

特别是像3.0  -> 5.0  ->6.0
2 楼 天明破晓 2011-08-21  
看了您的解释之后,首先我先表示惭愧,刚才有事出去了,然后我也说一下我不懂的地方:
上面说的是area只用于特殊的组件,而且也列举得很清楚,这我可以理解,但是:
<imagemap src="/img/sun.jpg" onClick="alert(event.area)">
  <area id="First" coords="0, 0, 100, 100"/>
  <area id="Second" shape="circle" coords="200, 200, 100"/>
</imagemap>


这段代码得到的是area的Id,而下面的代码,我没有查文档,我设想点击onClick with Hi它应该得到的是Hi,可得到的是null,这两段代码同出自zk的开发手册,但是为什么自身的解释存在这样的冲突,我觉得它应该是否还具有更加深奥的意义.我们没有挖掘出来的东西.
<window title="Test of JavaScript Utilities">   
   <html onClick='l.value = "onClick "+event.area'   
      onUser='l.value ="onUser " +org.zkoss.lang.Objects.toString(event.data)'><![CDATA[  
      <a href="javascript:;" onclick="comm.sendClick(this, 'Hi')">onClick with Hi</a>  
      <a href="javascript:;" onclick="comm.sendClick(this)">onClick with null</a>  
      <a href="javascript:;" onclick="comm.sendUser(this)">onUser with null</a>  
      <a href="javascript:;" onclick="comm.sendUser(this, 'One')">onUser with One</a>  
      <a href="javascript:;" onclick="comm.sendUser(this, 'One', 'Two')">onUser with [One, Two]</a>  
      <a href="javascript:;" onclick="comm.sendEvent(this, 'onUser', 'XYZ')">onUser with XYZ</a>  
   ]]></html>   
   <separator/>   
   <label id="l"/>   
</window><br>  


我不是钻牛角尖,只是觉得有不明后的地方就提出来,至于能不领悟和解决,那得看自己的学习和能力,如果有问题大家来解决,那也是一种快乐的学习.

感谢sun4love !!!
1 楼 sun4love 2011-08-21  
我看了一下MouseEvent的官方文档,

/** Returns the logical name of the area that the click occurs, or
* null if not available.
*
* <p>It is used only with some special components,
* that partition itself into several logical areas.
* <p>For example, <code>imagemap</code> and <code>chart</code>
* partition an image into multiple sections represented with
* the area component ({@link org.zkoss.zul.Area}).
* <p>If each partition is represented with {@link org.zkoss.zul.Area}, the
* return value is {@link org.zkoss.zul.Area#getId}, if it is assigned, or
* {@link org.zkoss.zul.Area#getUuid} if not assigned.
* To simplify the access, you can retrive it back with
* {@link #getAreaComponent}.
* @see #getAreaComponent
*/
public String getArea() {
return _area;
}


从上面的解释可以看出,getArea仅用于如下组件:

imagemap ,chart,以及有area表示的多个区域的image

相关推荐

Global site tag (gtag.js) - Google Analytics