按钮的。点击()命令无法在Chrome工作 [英] Button's .click() command not working in Chrome

查看:109
本文介绍了按钮的。点击()命令无法在Chrome工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个按钮

<asp:Button ID="submitRegionsButton" runat="server" Text="OK" OnClick="OnSubmitRegion" />

当我点击它,一切正常,但是当我有一个JavaScript函数中使用btn.click(叫),不执行命令的点击。该按钮被正确找到,但只是不工作,那么还是在我的code运行的OnClick功能背后

and when I click it, everything works as expected, however when I have a javascript function call it using btn.click(), the click command is not executed. The button is found properly but just doesn't then work or run the OnClick function in my code behind

任何想法?它工作在IE浏览器,没有测试火狐虽然

Any ideas? It works in IE, haven't tested firefox though

好吧,在Firefox的测试,这里是行不通的。一切工作的权利,直到实际调用。点击(),不知道为什么:/

Okay, tested in firefox, doesn't work there. Everything works right up until the actual call to .click(), no idea why :/

code调用点击:

    function dropDownProductBlur() {
        if (isItemClicked) {
            var combo = $find("<%= productDropDown.ClientID %>");
            var btnSubmitProd = $get(combo.get_id() + "_Footer" + "_submitProductsButton");
            if (btnSubmitProd)
                btnSubmitProd.click();
        }
    }

只是为了了解,该按钮包含在下拉列表中,并在下拉关闭时,听到卡嗒的按钮,点击此按钮手动工作(或者,嗯,应该..),并找到工作,发现按钮正常。

Just for understanding, the button is contained within a dropdown, and when the dropdown closes, it "clicks" the button (or, well, is supposed to..) clicking the button manually works, and the find works and finds the button properly.

推荐答案

我最近就遇到了这个问题,我自己。我认为,问题是,在JavaScript中,本。点击()时,无论是作为组件的OnClientClick事件,或一些其他处理完全。不知道这一点。

I recently ran into this problem myself. I believe the issue is that in javascript, this .click() is either treated as the component's onClientClick event, or something else entirely. Not sure on this.

在任何情况下,我的解决方案:
而不是调用的btnSubmitProd.click(),执行 __ doPostBack('富','酒吧'); 其中foo是一个任意名称(通常为组件,因此​​submitRegionButton)而酒吧是该名称的任意值,典型的事件(所以点击)(也有两个下划线那里,没有之一)。然后,在你的codebehind:

In any case, my solution: Instead of calling btnSubmitProd.click(), do __doPostBack('Foo', 'Bar'); where Foo is an arbitrary name (typically the component, so "submitRegionButton") and Bar is an arbitrary value for that name, typically the event (so "click") (also, there are TWO underscores there, not one). Then, in your codebehind:

try {
  if (Request["__EVENTTARGET".ToString() == "Foo" && Request["__EVENTARGUMENT"].ToString() == "Bar" {
    //call the codebehind directly here
    OnSubmitRegion(null null);
  }
}

我假设你的codebehind函数的形式为保护无效OnSubmitRegion(对象发件人,EventArgs e)条。如果您需要任何这些变量的值,事情变得更加复杂。如果没有,给上面的一个尝试。

I assume your codebehind function is of the form protected void OnSubmitRegion(object sender, EventArgs e). If you need the values for any of those variables, things get a little more complicated. If not, give the above a try.

这篇关于按钮的。点击()命令无法在Chrome工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆