按钮操作中带有回调的 JQuery UI 对话框无法打开第二个对话框

发布于 2024-11-08 11:30:02 字数 2011 浏览 2 评论 0原文

这似乎是一个常见的话题,但我还没有看到有人发布这个特定的版本。

<script>
$(document).ready(function() {
   $("#somebutton").click(function() {
       $.get("someurl", function(data){
          $("#PartsDialogDiv").html(data);
          $("#PartsDialogDiv").dialog("open");
       });
    });


   $("#PartsDialogDiv").dialog({
           autoOpen: false,
           width: 600,
           resizable: false,
           modal: true,
           buttons: {
               "Use Part": function() {
                   $.get("someurl", function(data){
                       $("#AnotherDIV").html(data);
                   });
                   $(this).dialog("close");
               },
               "Cancel": function () {
                   $(this).dialog("close");
               }
           }
     });
});
</script>
<div id="PartsDialogDiv"></div>
<div id="AnotherDIV"></div>

当我在执行“使用部件”按钮操作后按下调用 .dialog("open") 的按钮时,会发生什么情况,它无法打开。事实上,它指出:

Object doesn't support this property or method

我有一种感觉,第一次按“Use Part”时的回调无法保留 PartsDialogDiv 上的 dailog 设置,并且它不再知道该 div 可以调用该 jquery UI 方法。

将其全部包装在 $(document).ready() 中,我不确定如何处理将该 div 重新初始化为对话框而不将其放入“使用部分”按钮功能中。

有没有人经历过这种情况,并对如何处理这个问题有什么好的建议或建议?

先感谢您!

这是 MVC3,但不完全确定它是否相关。

回答(因为我要在发布后 8 小时才能回答我自己的问题): 我设法解决了它。珍和乔治康明斯都让我得出这样的结论:我的片面观点是不好的。

在我的部分观点中,我包含了这些脚本:

<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")"
       type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" 
       type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" 
       type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" 
       type="text/javascript"></script>

它们是自动生成的(或者我出于某种原因盲目地包含它们)并且是不需要的。我删除了它们,一切都按预期进行。

非常感谢大家抽出宝贵的时间!

this seems like a common topic, but I haven't seen anyone post this particular version.

<script>
$(document).ready(function() {
   $("#somebutton").click(function() {
       $.get("someurl", function(data){
          $("#PartsDialogDiv").html(data);
          $("#PartsDialogDiv").dialog("open");
       });
    });


   $("#PartsDialogDiv").dialog({
           autoOpen: false,
           width: 600,
           resizable: false,
           modal: true,
           buttons: {
               "Use Part": function() {
                   $.get("someurl", function(data){
                       $("#AnotherDIV").html(data);
                   });
                   $(this).dialog("close");
               },
               "Cancel": function () {
                   $(this).dialog("close");
               }
           }
     });
});
</script>
<div id="PartsDialogDiv"></div>
<div id="AnotherDIV"></div>

What happens when I press the button that calls the .dialog("open") after doing the "Use Part" button action is it fails to open. In fact, it states that:

Object doesn't support this property or method

I have a feeling that the callback on the first press of "Use Part" fails to keep the dailog setting on the PartsDialogDiv and it no longer knows that the div can have that jquery UI method called on it.

With it all wrapped in a $(document).ready(), I am unsure how to handle reinitializing that div to a dialog without putting it within the "Use Part" button function.

Has anybody experienced this and have any good tips or advice on how to handle this?

Thank you in advance!

This is MVC3, but not entirely sure it's relevant.

ANSWER (since I cannot answer my own question until 8 hours after this is posted):
I managed to resolve it. Jen and George Cummins both led me to this conclusion that my partial view was bad.

In my partial view I have these scripts included:

<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")"
       type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" 
       type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" 
       type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" 
       type="text/javascript"></script>

They were autogenerated (or I blindly included them for some reason) and are unneeded. I removed them and everything works as intended.

Thank you so much for your time everyone!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

枯寂 2024-11-15 11:30:02

听起来当“使用零件”按钮单击发生时,某些东西正在改变“#PartsDialogDiv”。我们需要查看“// Do Something”位置的代码才能确定,但​​您可以检查该代码并根据需要进行更改。具体来说,查找对 .destroy() 或 .disable() 的调用。

Sounds like something is altering "#PartsDialogDiv" when the "Use Part" button click occurs. We would need to see the code in the place of "// Do something" to be sure, but you can examine that code and alter it as necessary. Specifically, look for calls to .destroy() or .disable().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文