【问题标题】:Page loaded in div - Jquery dialog position only works the first time在 div 中加载的页面 - Jquery 对话框位置仅在第一次工作
【发布时间】:2015-09-19 21:23:59
【问题描述】:

我遇到了一些奇怪的问题,我似乎无法解决它。希望你们中的一个可以帮助我。

我正在将一个页面加载到一个 div 中(当点击某个链接时)

在这个 div(这是一个不同的页面)中,我显示了我的数据库中的一些数据。单击 jquery 对话框时,您可以编辑输入的数据。当表单被提交时,数据被编辑并显示编辑的数据。我已经编写了一些代码来将对话框定位在显示的信息旁边。这工作但只有一次......如果我尝试再次编辑数据,对话框将在默认位置(左上角页面)打开 - 如果我没有将页面加载到 div 中 - 所以单独加载页面它工作得很好时间。

我还发现很奇怪,我必须将 jquery 脚本嵌入 index.php 中才能使其工作,而不是在我包含的使用 jquery 的页面中。现在进入我的代码

<script>
 $(function(c) {

    $( "#dialog" ).dialog({
      autoOpen: false,
       maxWidth:260,
        maxHeight: 85,
        width: 260,
        height: 85,

        show: {
        effect: "blind",
        duration: 1000
        },
        position: { 
        my: 'left, top',
        at: 'right, top',
        of: $('#opener')
        },
        hide: {
        effect: "explode",
        duration: 1000
        }
    });
    $( "#opener" ).click(function() {
      $( "#dialog" ).dialog( "open" );
    });
    });

<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
        } ?>

<script type = "text/javascript">

    $(function(b) {
    $( "#naam" ).on('submit', function(){
    $(this).closest("#dialog").dialog("close");

          // gather the form data
          var data=$(this).serialize();
          // post data
          $.post('members.php', data , function(returnData){
                      // insert returned html 

                      $('#test').load('members.php')
          })

          return false; // stops browser from doing default submit process
    });

    });

    </script>

【问题讨论】:

  • 谁能帮我推动正确的方向? :(

标签: jquery forms dialog


【解决方案1】:

在我将封闭位置{} 放入$( "#dialog" ).dialog({ 之后,它出于某种原因起作用了。

【讨论】:

  • 这确实不能回答问题。您应该说明您能够用您的代码修复它,但您不知道为什么会这样。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-12
  • 1970-01-01
相关资源
最近更新 更多