0

我正在使用 asp.net 内容页面和 Jquery。我是 Jquery 的新手并使用 datepicker 和模态对话框。autoOpen:false如果我从下面共享的代码片段中删除了该行,Datepicker 工作正常,但模式对话框不起作用。当我单击图像按钮时,我需要触发模式对话框。

请帮助我,以下是我的 jquery 代码。

$(function () {
   var dialogshow = true;
   if (dialogshow) {
     $('#dialog').dialog({
      autoOpen: false,
      width: 600,
      closeOnEscape: true,
      resizable: false,
      draggable: true,
      modal: true,
      title: 'Add New Project',
       show: {
        effect: 'blind',
        duration: 1000
       },
       hide: {
        effect: 'explore',
        duration: 1000
       }
     });
    }
});

$("#ImgProjAdd").click(function () {
  $("#dialog").dialog("open");
  return false;
});

//my asp.net code to generate image button
<asp:ImageButton ID="ImgProjAdd" runat="server" ImageUrl="~/images/plus2.png" />
4

3 回答 3

1

而不是首先$("#ImgProjAdd")尝试使用“结束于”选择器$("[ID$=ImgProjAdd]")

控制 id 由 .Net 框架修改,通常生成的 id 以您使用的 id 结尾。

其次,$(...)像这样移动里面的点击定义:

$(function () {
   var dialogshow = true;
   if (dialogshow) {
     $('#dialog').dialog({
      autoOpen: false,
      width: 600,
      closeOnEscape: true,
      resizable: false,
      draggable: true,
      modal: true,
      title: 'Add New Project',
       show: {
        effect: 'blind',
        duration: 1000
       },
       hide: {
        effect: 'explore',
        duration: 1000
       }
     });
    }

    $("[ID$=ImgProjAdd]").click(function () {
      $("#dialog").dialog("open");
      return false;
    });
});
于 2013-08-12T06:39:57.463 回答
1

加载 DOM 时,“asp:ImageButton”不会生成相同的 ID='ImgProjAdd'。查看您的页面源并导航到“ImgProjAdd”,您将看到一个值被添加到它前面。您应该为生成的 ID 编写“点击”函数。

于 2013-08-12T06:37:50.973 回答
0
  function OpenJqueryDialog() {
            $('#dialog').dialog({ autoOpen: false, bigframe: true, modal: true, width: 450, closeOnEscape: true, resizable: false, show: { effect: 'blind', duration: 1000 }, hide: { effect: 'explore', duration: 1000} });
            $('#dialog').dialog('open');
                        $("#iframe").attr('src', 'AddProject.aspx');
            return false;
        }

 <div id="dialog" title="Add New Project" style="width: 600px; height: 250px; display: none;">
            <iframe id="iframe" width="100%" height="100%" marginwidth="0" marginheight="0" frameborder="0"
                scrolling="no" title="Add New Project"></iframe>
        </div>

<asp:ImageButton ID="ImgProjAdd" runat="server" OnClientClick="return OpenJqueryDialog();"
                                        ImageUrl="~/images/plus2.png" />
于 2013-08-13T04:42:25.543 回答