2013-12-23 20 views
-1

工作,我想建立一個類似於thisjQuery的模態確認不會在PHP

這個PHP頁面嵌入到父PHP頁面在最後一個PHP jQuery的模態確認對話框。

麻煩的是,雖然我能夠完美地在jsfiddle上工作,但我無法在我的php頁面上工作。

My jsfiddle version

我的jQuery塊:

var submitForm = $('#form_twake'); 
submit = false; 

$("#confirm").dialog({ 
    resizable: false, 
    height: 140, 
    modal: true, 
    autoOpen: false, 
    buttons: { 
     'Submit': function() { 
      $(this).dialog('close'); 
      submit = true; 
      submitForm.submit(); 
     }, 
     'Cancel': function() { 
      $(this).dialog('close'); 
     } 
    } 
}); 
$("#confirm").parent().appendTo($("#form_twake")); 

submitForm.submit(function() { 
    if (submit) { 
     return true; 
    } else { 
     $("#confirm").dialog('open'); 
     return false; 
    } 
}); 

HTML代碼:

<form id="form_twake" name="form_twake" method="POST" action="index.php"> 
    <div> 
    <input type="submit" value="Destroy" /> 
    </div> 
</form> 

<div id="confirm" title="Empty the recycle bin?"> 
    <p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>These items will be permanently deleted and cannot be recovered. Are you sure?</p> 
</div> 

逸岸, 'DIV ID確認' 的內容得到顯示各地呈現的PHP頁面。提交會提交表單,但不會彈出所需的確認信息。是否有任何jQuery專門爲PHP進行處理的順序?我已經完成了所有可能的研究,併爲我提供了一個可用的JSFiddle。我似乎無法超越!

任何幫助將非常感謝!

[編輯]添加php代碼;

這裏是CSS &庫:

<link rel="stylesheet" type="text/css" href="includes/style.css"> 
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css"> 
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> 
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script> 

PHP形式:

<form id="form_twake" name="form_twake" method="POST" action="index.php"> 
    <div class="box fade-in one"> 
     <center><img style="border:solid 2px #FFCC00;" src="<?php echo $bud ['profile_image_url'];?>" alt="Avi" hspace="5" vspace="5" border="5"/></center> 
     <?php echo $bud ['name'];?></br></br> 
     <input type="submit" value="Destroy" class="twake-button" /> 
    </div> 
</form> 
+1

jquery和PHP是完全無關的。您的所有服務器端PHP都是在javascript甚至有機會做任何事情之前完成的。 – Leeish

+0

上面的代碼是上面的代碼還是小提琴上的代碼?這聽起來像一個CSS問題?您是否包含jQuery UI的CSS文件? – Leeish

+0

謝謝,我明白,但我可以讓它在jsfiddle中工作,並且當我呈現我的php時它完全中斷。我也驗證了導入的jQuery庫,以防PHP不能識別jQuery代碼塊。 – PopoFibo

回答

1

在你的CSS文件中,已確認的div默認隱藏:

#confirm { 
    display: hidden; 
} 

然後,確保您在頁面加載後運行您的JavaScript代碼。這可以用下面的代碼完成:

<script type="text/javascript"> 

$(function() { 
    // put your code here. 
}); 

</script>