0

我正在尝试以下代码在单击按钮时触发文本框上的单击事件,因为 focus() 函数在 IE8 中不起作用

function simulateClick(elm) {
  var evt = document.createEvent("MouseEvents");
  evt.initMouseEvent("click", true, true, window,
      0, 0, 0, 0, 0, false, false, false, false, 0, null);
  var canceled = !elm.dispatchEvent(evt);
  if(canceled) {
     // A handler called preventDefault
     // uh-oh, did some XSS hack your site?
  } else {
     // None of the handlers called preventDefault
     // do stuff
  }
}

如果元素的类型是复选框而不是文本框,则此代码可以正常工作,我可能需要添加什么吗?

4

1 回答 1

0

这是焦点的代码

function ResponseEnd(sender, args) {
        if (args.get_eventArgument().indexOf("Filter") != -1) {
            var grid = document.getElementById("<%= radGridEnquiries.ClientID %>");
            var label =  $(grid).children("table").children("tbody").children(".rgRow").children("td:has(span)").children("span")[0];
            if (label != null) {
                label.focus();
            }
            else {
                var noRecTemp = $(grid).children("table").children("tbody").children("tr.rgNoRecords").children("td:has(div)").children("div");
                noRecTemp.focus();
            }
        }

        if (postInProgress)
            postInProgress = false;
    }

真实情况是我在 Telerik RadGrid 中有一些文本框设置为过滤器并且没有过滤器图标,但是当用户发布过滤器并且请求在 IE8 中完成时,过滤器文本框仍然具有焦点,阻止用户输入新过滤器,除非单击再次手动在文本框上

PS 抱歉,如果这篇文章被视为答案,但无法使用正确的缩进代码更新此问题。谢谢

于 2010-12-16T10:19:05.897 回答