2015-04-22 41 views
0

我不是一個js的傢伙。我有這兩個js函數。jquery對話框干擾他們

$(document).ready(function() { 

    $(function() { 
     $("#dialog").dialog({ 
      autoOpen: false, 
      modal: true, 
      width: 500 
     }); 
     $("#button").on("click", function() { 
      $("#dialog").dialog("open"); 
     }); 
    }); 
}); 

function editar(id) { 
    $.ajax({ 
     url: "../controllers/editarEvento_controller.php?idEvento="+id, 
     success: function (data) { 
      $("#editarEvento").html(data).dialog({ 
       modal: true, 
       width: 500 
      }).dialog("open"); 
     } 
    }); 
} 

HTML按鈕和div的外觀如何。

<input id="button" type="button" class="botonAnadir" value="+Añadir evento"> 
<input type='button' class='botonGris' onclick='editar(some id);' value='Editar'/> 

<div id="dialog" title="Añadir un evento"> a form inside </div> 

<div id="editarEvento" title="Editar evento"></div> 

時間一旦我點擊editarEvento我無法打開的對話框了,並引發了我:

" Error: cannot call methods on dialog prior to initialization; attempted to call method 'open'".

我想這必須要準備的功能,我不知道,我只是走功能從一些地方:/

謝謝。

回答

0

使用下面的語法,而在HTML打印php變量的值:<?php echo $id; ?>

<input type='button' class='botonGris' onclick='editar("<?php echo $id; ?>");' value='Editar'/> 
                 ^^^^^^^^^^^^^^^^^^ 

您不必同時使用

  • $(document).ready(function() {
  • $(function() {

兩者都是相同的。你可以使用它們中的任何一個,比如:

$(function() {//or $(document).ready(function() { 
    $("#dialog").dialog({ 
     autoOpen: false, 
     modal: true, 
     width: 500 
    }); 
    $("#button").on("click", function() { 
     $("#dialog").dialog("open"); 
    }); 
}); 
+0

這個輸入是在php回聲裏面,我只是編輯過來試圖避免誤解,對不起。 我刪除了$(document).ready(function(),但沒有任何改變。 – otrolopezmas