将选择器传递给dialog.position()不能按预期工作

时间:2022-08-26 09:00:52

I'm using jquery-ui version 1.11.0 to create dialogs. I can create a dialog as expected:

我正在使用jquery-ui版本1.11.0来创建对话框。我可以按预期创建一个对话框:

onClick: function(e){
  $('#result').dialog({height:400, width:315, position:{at:"center", of:"#"+e.key}})
  var xmlhttp = new XMLHttpRequest();
  xmlhttp.onreadystatechange = function () {
    if(xmlhttp.status == 200 && xmlhttp.readyState == 4){
      response = xmlhttp.responseText;
      $('#result').dialog().html(response);
    }
  };
  xmlhttp.open("GET", "floorplan.php?cube=" + encodeURIComponent(cubes[e.key]), true);
  xmlhttp.send();
}

The dialog opens and is assigned the response as expected. However, the dialog's position defaults to the center of the window even though I've passed a selector to the position option.

该对话框打开,并按预期分配响应。但是,即使我已经将选择器传递给位置选项,对话框的位置也默认为窗口的中心。

I've used console.log() and alert() to verify that e.key is the id of the area element that I've clicked on to fire this event.

我已经使用console.log()和alert()来验证e.key是我点击的区域元素的id来触发此事件。

Any suggestions? The documention says I should be able to pass a Selector to the position(of:) option. Has anyone else been able to get this to work as expected?

有什么建议么?文档说我应该能够将选择器传递到(:)选项的位置。有没有其他人能够按预期工作?

1 个解决方案

#1


0  

Works as expected in jsfiddle.

在jsfiddle中按预期工作。

I did end up using the click Event to determine the position of the dialog, but it was doubly wrapped for whatever reason:

我最终使用click事件来确定对话框的位置,但是由于某种原因它被双重包装:

$('#result').dialog({height:100, width:315, position:{my: "left top", at:"right bottom", of:e.e}});

#1


0  

Works as expected in jsfiddle.

在jsfiddle中按预期工作。

I did end up using the click Event to determine the position of the dialog, but it was doubly wrapped for whatever reason:

我最终使用click事件来确定对话框的位置,但是由于某种原因它被双重包装:

$('#result').dialog({height:100, width:315, position:{my: "left top", at:"right bottom", of:e.e}});