繁体   English   中英

回传不适用于Safari中的鼠标单击

[英]Postback not working on mouse click in Safari

因此,我有一个下拉上下文框,用于选择要使用的项目。

现在,一切似乎都可以在除Safari之外的所有浏览器上运行。 我有一个类型功能,如果您专注于该框并在其中输入名称并按Enter,则可以在野生动物园中正常工作。 但是我的问题是鼠标单击。 如果我从下拉菜单中选择一项,然后单击它,则在按键盘上的Enter键之前,回发不起作用。

这是我的.ascx.cs文件

...
if (cboContext.Visible)
    {
        string postBackFunction = "function contextPostback() {\n"
        + "var newValue = document.getElementById(\"" + cboContext.ClientID + "\").value;\n"
        + "if (newValue != " + cboContext.SelectedValue + ") " + Page.ClientScript.GetPostBackEventReference(cboContext, "") + ";\n}";

        Page.ClientScript.RegisterClientScriptBlock(typeof(string), "contextPostback", postBackFunction, true);

        if (Request.UserAgent.ToLower().IndexOf("chrome") > -1)
        {
            cboContext.Attributes.Add("onkeypress", "if (typeAhead(event,'" + cboContext.ClientID + "') == 1) contextPostback();");
            cboContext.Attributes.Add("onclick", "contextPostback();");
        }
        else if (Request.UserAgent.ToLower().IndexOf("safari") > -1)
        {
            cboContext.Attributes.Add("onclick", "contextPostback();");
            cboContext.Attributes.Add("onkeypress", "if (typeAhead(event,'" + cboContext.ClientID + "') == 1) contextPostback();");
            cboContext.Attributes.Add("onkeydown", "if (typeAhead(event,'" + cboContext.ClientID + "') == 1) contextPostback();");
            cboContext.Attributes.Add("onkeyup", "if (typeAhead(event,'" + cboContext.ClientID + "') == 1) contextPostback();");
        }
        else
        {

            cboContext.Attributes.Add("onkeydown", "if (typeAhead(event,'" + cboContext.ClientID + "') == 1) contextPostback();");
            cboContext.Attributes.Add("onclick", "contextPostback();");
        }
    }

这是typeAhead()函数

function typeAhead(e, nextFocus) {

//don't trap Ctrl+keys
if ((window.event && !window.event.ctrlKey) || (e && !e.ctrlKey)) {

    // timer for current event
    var now = new Date();

    ....
    if (inputBuffer.accumString == "" || now - inputBuffer.last < inputBuffer.delay) {
        //check for browsers
        var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
        var is_safari = navigator.userAgent.toLowerCase().indexOf('safari') > -1;
        // make shortcut event object reference
        var evt = e || window.event;
        // get reference to the select element
        var selectElem = evt.target || evt.srcElement;
        // get typed character ASCII value
        var charCode = evt.keyCode || evt.which;
        // get the actual character, converted to uppercase
        var newChar = "";
        // get reference to the actual form selection list
        // added cross browser fix to enable the context switcher to work properly
        if (is_chrome) {
            var selection = document.getElementById("ctl00_ContextSwitch1_cboContext").selectedIndex;
        }
        else {
            var selection = document.getElementById(nextFocus);
        }
....

现在,我在chrome浏览器的typeAhead中有一个部分,但我尝试进行野生动物园的所有操作似乎都不允许我使用鼠标单击来选择项。

任何帮助,将不胜感激。

简单修复。 Safari可以识别onchange因此一旦我添加了它,它就可以正常工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM