jquery对话框只在第一次打开

时间:2013-09-03 06:45:44

标签: php javascript

我有jquery对话框,当我点击按钮时它会打开,但只有当我关闭它并第二次点击同一个按钮时它才会出现。这是我的代码:

脚本:

$(function () {
    $("#dialogPicture").dialog({
        autoOpen: false
    });    

    $(".buttonClass").on("click", function () {

        // get the div element with the id dialogClass contained at the same scope as button!    

        var id = ($(this).siblings(".dialogClass").attr("id"));
        $("#" + id).dialog({
            autoOpen: false
        });
        $("#" + id).dialog("open").css({
            "font-size": "13px"
        });    
    });    
});

HTML:

<td>
   <?=$row['NOMER']?><input id="btn2" class="buttonClass" type="button" value="ВИЖ" />
   <div class="dialogClass" id="dialogPicture_<?=$row['NOMER'];?>" style="display:none;">
      <table class="bilet">
         <tr>
            <h2>
               <td colspan="4">
                  <div align="center"><strong>ПРЕВОЗЕН БИЛЕТ</strong></div>
               </td>
            </h2>
         </tr>
         <p>
            <tr >
         <td colspan="2" align="right">
      </table>
   </div>

2 个答案:

答案 0 :(得分:0)

你可以尝试一下。

您应该使用此代码销毁按钮部分中的对话框

   $("#TestMenuDialog").dialog("close").dialog("destroy").remove();

 var NewDialog = $('<div id="TestMenuDialog"><p style="color:Red;style="font-size:7x;font-weight:normal">' + Message + '</p></div>');
        NewDialog.dialog({
            modal: false,
            title: "Test Dialog",
            height: 200,
            width: 375,
            show: 'clip',
            hide: 'clip',
            buttons: [
                  { text: "OK", click: function () { $(this).dialog("close").dialog("destroy").remove(); } }
            ]
        });

检查Jfiddle Link它工作正常

http://jsfiddle.net/zpP3c/1/

答案 1 :(得分:0)

我认为问题是每次按下按钮都会创建一个新的对话框实例 尝试初始化脚本开头的所有对话框,让按钮只打开它们 另一个问题是初始化后对话框div不再出现在桌面上:
<div id="btn<?=$row['NOMER']?>" .....

        $(function () {
            $(".dialogClass").each(function(){
                $(this).dialog({ autoOpen: false });
            }); 

                $(".buttonClass").on("click", function () {

                // get the div element with the id dialogClass contained at the same scope as button!    

                var btnId = ($(this).attr("id"));
                btnId = btnId.replace("btn","");
                $("#dialogPicture_" + btnId).dialog("open").css({
                    "font-size": "13px"
                });    
            });   
        });
相关问题