开发者

Simulate Textbox Click to get focus

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 prevent开发者_如何学JAVADefault
     // 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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜