简体   繁体   English

为什么我的jQuery UI对话框不起作用?

[英]Why won't my jQuery UI dialog work?

Why won't my jQuery UI dialog work? 为什么我的jQuery UI对话框不起作用?

It works if I put the div on the page in the html but I want to rather dynamically insert it as below then remove it with a click event. 如果我将div放在html的页面上,但我想像下面那样动态地插入它,然后用click事件将其删除,则它可以工作。

var d = $("<div id='my' >any text</div>");

d.dialog({

     modal: true

});

Later I want to close it in another event with 后来我想在另一个事件中关闭它

$('td').click(function(){

   $("#my").dialog("close");

)};

You create the element, but don't seem to add it to the DOM? 您创建了元素,但是似乎没有将其添加到DOM中吗? If you use the .appendTo() method, you can add it to the DOM, prior to calling the .dialog() method. 如果使用.appendTo()方法,则可以在调用.dialog()方法之前将其添加到DOM中。

Try something like this instead 尝试这样的事情

$("<div id='my'>any text</div>").appendTo("body"); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM