开发者

JQuery select() function issue in IE8

I am using IE8, I want to show a form with one text field as a dialog window and show the cursor pointer in the text field by default.

This happens when user clicks on a link in the webpage. For this I have writter JQuery code as below. This works fine in Firefox but not in IE8 (that is cursor is not showing in the first text box). Any suggestions?

$("#show_myform").click(function(event) {
                    $("#myform").dialog({modal : true,draggable : false,resizable : false});
                 开发者_C百科   $("#myform :text:eq(0)").select();
});


One important thing to bear in mind, is that you should not be recreating your dialog multiple times. (See: http://blog.nemikor.com/2009/04/08/basic-usage-of-the-jquery-ui-dialog/ for a more in depth explanation) In your existing code, your dialog object will be recreated every time you click the show_myform item.

$("#myform").dialog({
  modal : true,
  draggable : false,
  resizable : false,
  open: function(event, ui) { 
    $("#myform :text:first").focus();
  },
  autoOpen: false
});

$("#show_myform").click(function(event) {
  $('#myform').dialog('open');
  return false;
});


I believe you want to use the .focus() method and perhaps you would want to focus on open of the modal dialog

$("#show_myform").click(function(event) {
  $("#myform").dialog({
    modal : true,
    draggable : false,
    resizable : false,
    open: function(event, ui) { 
      $("#myform :text:eq(0)").focus();
    }
  });
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜