문제

I am trying the following code to fire click event on a textbox while clicking on a button as the focus() function is not working in 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
  }
}

This code works fine if the element is of type checkbox but not textbox, is there anything I might need to add?

도움이 되었습니까?

해결책

This is the code for focus

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;
    }

The real scenario is I have some textboxes set as filters in a Telerik RadGrid and having no filter icons but when the user posts a filter and the request is finished in IE8 the filter textbox is still with focus preventing the user to input new filters unless clicks on the textbox manually again

P.S. Sorry if this post is seen as answer but couldn't update this question with proper indented code. Thanks

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top