0

我正在使用下面的代码来获取 Jquery UI 弹出窗口,但它没有返回值并且弹出框正在关闭

当我单击按钮时,我需要它必须作为确认框..!

代码 :

<style type="text/css" >
        .ui-widget-header, .ui-widget-content
    { color: red !important;}
</style>
<script type="text/javascript">
    $(document).ready(function () {
        var $myDialog = $('<div></div>')
        .html('You are going to Lock the Record.<br/>Click OK to confirm.  Click Cancel to stop this action.')
        .dialog({
            autoOpen: false,
            title: 'Confirm..?',
            buttons: { "OK": function () {
                $(this).dialog("close");

            }, "Cancel": function () {
                $(this).dialog("close");

            }
            }
        });

        $(function fn() {
            $('#Button1').click(function (e) {
                return $myDialog.dialog('open');

            });
        });
    });
</script>


<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="return fn() onclick="Button1_Click"/>
4

5 回答 5

1
$(function fn() {

 });

你在另一个里面有一个dom准备好的功能。你需要删除上面的块......

 $(document).ready(function () {
        var $myDialog = $('<div></div>')
        .html('You are going to Lock the Record.<br/>Click OK to confirm.  Click Cancel to stop this action.')
        .dialog({
            autoOpen: false,
            title: 'Confirm..?',
            buttons: { "OK": function () {
                $(this).dialog("close");

            }, "Cancel": function () {
                $(this).dialog("close");

            }
            }
        });
            $('<%=Button1.ClientID%>').click(function (e) {
                $myDialog.dialog('open');
                return false;

            });
    });

我希望这是正确的。

于 2013-02-18T08:48:30.357 回答
0

在 HTML 输出中是否以 ID 'Button1' 呈现 asp.net 按钮?如果是,您可以尝试以下代码(修改您的代码)

代码 :

<style type="text/css" >
        .ui-widget-header, .ui-widget-content
    { color: red !important;}
</style>
<script type="text/javascript">
    $(document).ready(function () {
        var $myDialog = $('<div></div>')
        .html('You are going to Lock the Record.<br/>Click OK to confirm.  Click Cancel to stop this action.')
        .dialog({
            autoOpen: false,
            title: 'Confirm..?',
            buttons: { "OK": function () {
                $(this).dialog("close");

            }, "Cancel": function () {
                $(this).dialog("close");

            }
            }
        });

         $('#Button1').click(function (e) {
               $myDialog.dialog('open');
               e.preventDefault();      
          });
      });
</script>


<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click"/>
于 2013-02-18T08:41:43.810 回答
0

将 CSS 类删除添加到控件,然后应用 jquery 确认对话框:

$('.delete').click(function () {
          return confirm('Are you sure you wish to delete this record?'); 
    });
于 2013-09-25T18:20:49.020 回答
0

.dialog('open') 将始终立即返回,它不会等待用户操作。

您需要更改代码以触发 Button1 控件的回发。而不是依赖返回值。

有关使用 JavaScript触发回发ASP.NET 回发的信息,请参见此处

编辑

<style type="text/css" >
        .ui-widget-header, .ui-widget-content
    { color: red !important;}
</style>
<script type="text/javascript">
    $(document).ready(function () {
        var $myDialog = $('<div></div>')
        .html('You are going to Lock the Record.<br/>Click OK to confirm.  Click Cancel to stop this action.')
        .dialog({
            autoOpen: false,
            title: 'Confirm..?',
            buttons: { "OK": function () {
                $(this).dialog("close");

__doPostBack("<%=Button1.ClientID %>","");

            }, "Cancel": function () {
                $(this).dialog("close");

            }
            }
        });

        $(function fn() {
            $('#Button1').click(function (e) {
                return $myDialog.dialog('open');

            });
        });
    });
</script>


<asp:Button ID="Button1" runat="server" UseSubmitBehavior="false" Text="Button" OnClientClick="return fn()" onclick="Button1_Click"/>
于 2013-02-18T08:40:15.920 回答
0

很难理解你的 dom 的结构。

但我会给你一个可行的解决方案

<div id="someDialog">some controls or text or whatever you want to show./div>// add it to your page.

然后使用 Jquery 和 Jquery UI 库,将其放入 head 标签中

$(function(){
$('#someDialog').dialog({ autoOpen: false,
            title: 'Confirm..?',
            buttons: { "OK": function () {
                if(confirm("are you sure you want to close the dialog))
                     $(this).dialog("close");

            }, "Cancel": function () {
                $(this).dialog("close");

            });


 $('#Button1').click(function (e) {
                $('#someDialog').dialog('open');

            }); // without return statement. 
});
于 2013-02-18T08:40:38.680 回答