JQUERY 使用一个带有相应按钮的对话框打开表单

JQUERY using one Dialog open form with corresponding button

希望大家能帮助我/推动我朝着正确的方向前进。 情况如下。我有几种形式,点击时应该弹出(页内)。为实现这一点,我使用了 JQUERY 的对话功能,效果很好。唯一的问题是我的页面开始包含大量代码,因为我为每个表单提供了自己的对话框。有没有办法结合使用 1 个对话框的功能? (所以把所有东西都放在一个函数中? - 或者根据按下哪个按钮将表单加载到对话框中?我在网上做了很多搜索但我找不到任何东西可以让我朝着正确的方向推动...... .hope yall willing and able to help me. Anyways thanks advance.(我只展示了前 2 个功能......我还有大约 6 个)

<script>
    $(function(c) {
        $( "#dialog" ).dialog({
            autoOpen: false,
            maxWidth:260,
            maxHeight: 85,
            width: 260,
            height: 85,
            show: {
                effect: "blind",
                duration: 1000
            },
            hide: {
                effect: "explode",
                duration: 1000
            }
        });

        $( "#dialog" ).dialog({
            position: { 
                my: 'left, top',
                at: 'right, top',
                of: $('#opener')
            }
        });
        $( "#opener" ).click(function() {
            $( "#dialog" ).dialog( "open" );
        });
    });

    $(function(s) {
        $( "#dialog2" ).dialog({
            autoOpen: false,
            maxWidth:300,
            maxHeight: 85,
            width: 300,
            height: 85,
            show: {
                effect: "blind",
                duration: 1000
            },
            hide: {
                effect: "explode",
                duration: 1000
            }
        });

       $( "#dialog2" ).dialog({
           position: { 
               my: 'left, top',
               at: 'right, top',
               of: $('#opener2')
           }
       });

       $( "#opener2" ).click(function() {
           $( "#dialog2" ).dialog( "open" );
       });
 </script>
 <body>
  <?php
    if(!empty($row['voornaam'])){
            ?>
            <div  id="dialog" >Naam<br>
                <p><form method="post"  id="naam"> <input type="text" value="<?php echo $row['voornaam'];?>" name="voornaam"  size="8"/> <input type="text" value="<?php echo $row['achternaam'];?>" name="achternaam"  size="8"/>&nbsp;<input type="submit" value="opslaan" > </form> 
            </div>
        <button id="opener" border="0" color="white"> <?php echo $row['voornaam'] . " " . $row['achternaam']  ;?> &nbsp; <img src="edit.png" width="10" height="10"></button>

        <?php
        } ?>
<?php
    if(!empty($row['gebooredatum'])){
        ?><div id="dialog2" >Geboortedatum<br>
        <p><form method="post" id="leeftijd" > <input type="text" value="" name="geboortedatum" placeholder="<?php echo $row['gebooredatum'];?>" size="11"/> &nbsp;<input type="submit" value="opslaan" > </form> 
        </div>
        <button id="opener2" border="0" color="white"> <?php echo $leeftijd   ;?>&nbsp; Jaar &nbsp; <img src="edit.png" width="10" height="10"></button>


        <?php
    } else {?>
<div  id="dialog2">Geboortedatum<br>
  <p><form method="post" id="leeftijd"> <input type="text" name="geboortedatum" placeholder="dd-mm-jjjj" size="11"/>  <input type="submit" value="opslaan" "size="3"></form></p>
</div>
<button id="opener2" border="0" color="white"><?php echo "Voeg je geboortedatum toe";?> &nbsp;<img src="edit.png" width="10" height="10"></button>
    <?php } ?>

</body>
</html>

您可以使用 jquery 小部件提供的打开事件。在此事件中,您可以放置​​一些逻辑来确定要在对话框中显示的内容。

http://api.jqueryui.com/dialog/#event-open