firefox下模拟click事件
来源:互联网 发布:2018人工智能国际大会 编辑:程序博客网 时间:2024/04/30 09:20
<a href="#" onclick="test(1)" id="a3">hello</a>
<a href="#" onclick="test2(1)" id="b3">hello2</a>
<script language="javascript">
<!--
function test(num)
{
window.alert(num);
}
function test2(num)
{
if(document.all)
document.getElementById("a3").click();
else
{
var evt = document.createEvent("MouseEvents");
evt.initEvent("click", true, true);
document.getElementById("a3").dispatchEvent(evt);
}
}
//-->
升级你的FIREFOX!
opera可以再改一下
<img id="a" src="/a.jpg" onclick="alert('a');"/><div onclick="clickObj('a')">click me</div>
<script language="javascript">
<!--
function clickObj(o){
var o = document.getElementById(o);
if( document.all && typeof( document.all ) == "object" ) //IE
{
o.fireEvent("onclick");
}
else
{
var e = document.createEvent('MouseEvent');
e.initEvent('click',false,false);
o.dispatchEvent(e);
}
}
//-->
</script>
Fix for Firefox click() event issue
Firefox does not support the javascript click() event on a hyperlink. So doing something like:
<asp:LinkButton ID="lnkMyButton" runat="server">My Button To Click</asp:LinkButton>
<a href="#" onclick="document.getElementById('lnkMyButton').click();">Click this to click the other link!</a>
This will work correctly in Internet Explorer but nothing will happen when you execute this javascript in FireFox.
This is because the javascript line in Firefox has the click() event and Firefox does not understand this event for hyperlinks (which is what an ASP.NET LinkButton control is rendered as on page load):
document.getElementById('lnkMyButton').click();
Workaround 1:
Instead of using a LinkButton control, use a Button control instead. Firefox does support the click() event for input type=button HTML controls. So you could change the code to this:
<asp:Button ID="btnMyButton" runat="server" />
<a href="#" onclick="document.getElementById('btnMyButton').click();">Click this to click the other button!</a>
Workaround 2:
If you can’t change the element to a Button control instead of a LinkButton, you can simulate the postback event by calling the method that .NET calls in the background when you click on the LinkButton control directly. This event is called __doPostBack() and takes the ID name of the control that you want to cause a postback. So you could change the code to this:
<asp:LinkButton ID="lnkMyButton" runat="server">My Button To Click</asp:LinkButton>
<a href="#" onclick="__doPostBack('lnkMyButton', '');">Click this to click the other link!</a>
The nice thing about this one is that even if this is in an ASP.NET AJAX UpdatePanel, it will still do the asynchronous postbacks correctly and post the link button.
- firefox下模拟click事件
- FireFox模拟click事件
- firefox下js触发click事件-->网转:
- FireFox与IE 下js兼容触发click事件
- FireFox与IE 下js兼容触发click事件
- click事件 兼容 IE Firefox
- 模拟调用Button Click事件
- FireFox与IE 下js兼容触发click事件的代码
- FireFox与IE 下js兼容触发click事件的代码
- FireFox与IE 下js兼容触发click事件的代码
- 【WebGUI】——IE,Firefox下通用的js触发click事件方法
- Angular解决IE和Firefox下button内部元素ng-click事件被屏蔽
- android开发模拟click点击事件
- VC++ 模拟"CLICK事件"关闭指定窗口
- safari浏览器实现模拟click点击事件
- 20170914 js模拟事件,什么click()都是伪模拟
- IE 下 img click 事件 src 不起作用
- 多种形态下的 click 事件
- 应用程序间发送消息 c# SendMessage WM_COPYDATA
- 如何定义Xsd文件
- ant教程
- 创建一个带滚动条的div
- Rails的表单helper: select
- firefox下模拟click事件
- 开发GNU软件之三
- C#反射实例讲解
- 我们为什么要全民支持蔡铭超?---赵丽华
- 利用API函数向外部应用程序发送消息收藏
- ajax缓存问题解决
- JBoss SSO学习笔记4 openldap
- SIP的各种实现及相关资源(更新中...)
- webkit为什么不能显示中文