我通過ajax提交表單,並在同一頁面上顯示添加的字段,以及編輯和刪除按鈕。已添加的字段顯示在頁面加載和進一步添加通過ajax顯示..刪除按鈕(添加在提交ajax後)沒有采取任何行動點擊即使在頁面加載刪除按鈕.. 我是否對jquery有一些誤解,並弄錯了,我該如何讓它工作做jquery仍然作用與另外的dom元素一樣通過ajax作爲已經顯示了dom元素?
從db中已經添加的字段是
....
<script type="text/javascript">
$(function()
{
$("#edit2").click(function(e) {
$("#username").val($("#u_name_2").text());
$("#uemail").val($("#u_email_2").text());
$("#editdata").html('Edit and Save') ;
$(".hiddclass").val('2');
});
});
</script>
<div id="info_2">
<div id="formdisplay">
<table class="table table-striped">
<tbody><tr>
<td> Username</td>
<td id="u_name_2">Sachin</td>
</tr>
<tr>
<td> Email :</td>
<td id="u_email_2">[email protected]</td>
</tr>
</tbody></table>
</div>
<a class="btn btn-info" id="edit2" type="button" href="#editform">Edit</a>
<a class="btn btn-danger delete" id="delete_2" type="button" href="#editform">Delete</a>
</div>
....
後提交關於Ajax中,顯示值是
<script type="text/javascript">
$(function()
{
$("#edit14 ").click(function(e) {
$("#username").val($("#u_name_14").text());
$("#uemail").val($("#u_email_14").text());
$("#editdata").html('Edit and Save') ;
$(".hiddclass").val('14');
});
});
</script>
<div id="info_14">
<div id="formdisplay">
<table class="table table-striped">
<tbody><tr>
<td> Username</td>
<td id="u_name_14"> ghg</td>
</tr>
<tr>
<td> Email :</td>
<td id="u_email_14">hj</td>
</tr>
</tbody></table>
</div>
<a class="btn btn-info" id="edit14" type="button" href="#editform">Edit</a>
<a class="btn btn-danger delete" id="delete_14" type="button" href="#editform">Delete</a>
</div>
刪除按鈕的點擊我打電話這是工作的罰款從DB已經顯示DIV jQuery的,但對於第二種情況,當我打電話的股利形式AJAX刪除按鈕並不像案例1
功能<script type="text/javascript">
$(function()
{
$(".delete").click(function(e) {
var r=confirm("Sure Want To Change Status?")
{
$id=$(this).parent().attr('id');
alert($id);
$.ajax({
type:'GET',
url: "include/process.php",
data: {id: $id, todel:'Delete' },
cache: true,
async : false,
error: function(){
alert ('error');
},
success: function(data)
{
alert(data);
// on_success_my_action
}
});
return false;
}
});
});
的$(document)。在( '點擊', '.delete',函數(E){}; –
如果你已經回答了你會得到+1 :)謝謝反正 – atjoshi