click方法可以用来模拟用户点击。有的浏览器中所有元素都具有click方法,有的浏览器则没有。如下

IE6/7/8/9/Opera12/Firefox5 Safari5/Chrome12
INPUT[type=text]
INPUT[type=password]
INPUT[type=radio]
INPUT[type=checkbox]
INPUT[type=button]
INPUT[type=submit]
INPUT[type=image]
INPUT[type=hidden]
INPUT[type=reset]
INPUT[type=submit]
INPUT[type=file]1
BUTTON[type=button]
支持 支持
other 支持 不支持

即Safari/Chrome没有完全支持click方法。click方法写进了HTML5草案,相信不久的将来Safari/Chrome也会支持。

需要注意的Firefox5之前的版本并不是所有元素都支持click方法,从w3help当时测试结果即可看出。

Mozilla官方也有以下一段话

Prior to Gecko 5.0 (Firefox 5.0 / Thunderbird 5.0 / SeaMonkey 2.2), Gecko didn't implement the click method on other elements that might be expected to respond to mouse–clicks such as links (A elements), nor will it necessarily fire the click event of other elements. However, now it is supported by all elements, as required by HTML5.  

虽然Firefox5现在对所有元素都添加了click方法,仍需注意它的click方法触发不了A的默认行为。IE/Opera却可以。

相关:

东国提供测试用例 

http://w3help.org/zh-cn/causes/SD9025  

https://developer.mozilla.org/en/DOM/element.click 

http://msdn.microsoft.com/en-us/library/ms536363(VS.85).aspx 

作者: snandy 发表于 2011-07-31 10:12 原文链接

推荐.NET配套的通用数据层ORM框架:CYQ.Data 通用数据层框架
新浪微博粉丝精灵,刷粉丝、刷评论、刷转发、企业商家微博营销必备工具"