0
我的頁面初始加載下面我有jQuery的DOM元素
<div class="display-none">
<div id="add-employee-container">
<form name="create_employee" id="create_employee" method="post" action="#" onsubmit="return false;">
<label><span class="text-red">* </span>First Name:</label><input name="firstname" id="firstname" type="text" class="required"/><span></span><br /><br />
<label><span class="text-red">* </span>Middle Name:</label><input name="middlename" id="middlename" type="text" class="required"/><span></span><br /><br />
<label><span class="text-red">* </span>Last Name:</label><input name="lastname" id="lastname" type="text" class="required"/><span></span><br /><br />
<label><span class="text-red">* </span>Birth Day:</label><input name="bday" id="bday" type="text" class="required" id="date-pick"/><span></span><br /><br />
<label>Tel No.:</label><input name="telno" id="telno" type="text" /><span></span><br /><br />
<label><span class="text-red">* </span>Mobile No.:</label><input name="mobileno" id="mobileno" type="text" class="required"/><span></span><br /><br />
<label><span class="text-red">* </span>Home Address:</label><input name="homeads" id="homeads" type="text" class="required"/><span></span><br /><br />
<div class="submit-container"><span class="pad-right-5"><input name="" type="submit" value="Create" class="submit-button create"/></span><input name="" type="button" value="Cancel" class="submit-button cancel-button"/></div>
</form>
</div>
</div>
$(".add-employee").colorbox({
width:"50%",
inline:true,
title:' ',
href:"#add-employee-container"
});
形式後這種形式是提交和使用的CodeIgniter控制器與數據庫保存。我將它添加到我的記錄容器列表中。我現在的問題是我想修改一個已經添加的記錄。一旦我點擊一條記錄,然後在我的控制器中通過jquery post提交(id),並在我的colorbox中傳遞html,現在創建按鈕不起作用,即使我嘗試提交表單仍然不起作用。我認爲這是因爲它沒有被識別爲dom元素,因爲我通過ajax顯示它,而且還有更多的頁面初始加載,我已經有了一個具有相同元素的表單。下面
$('.edit').click(function(){
var employee_id = $(this).attr('name');
$.post("<?php echo site_url('admin/employee/edit') ?>", {employee_id: employee_id},
function (data){
$('#add-employee-container').html(data);
$.fn.colorbox({
width:"50%",
html:data,
});
},'html'
)
});
我的PHP函數的記錄
編輯編輯記錄
function edit()
{
$employee_info = $this->admin_model->get_employee(false,false,$this->input->post('employee_id'));
$html = '<form name="create_employee" id="create_employee" method="post" action="#" onsubmit="return false;">
<h3 class="title-highlight-light-pink">Edit Employee Record</h3>
<h2><span class="text-red">* <span style="font-style:italic">Required</span></span></h2>
<div id="add-employee">
<label><span class="text-red">* </span>Referal:</label>
<select name="referal" id="referal">
<option value="" selected="selected">Select referal</option>
<option value="2">Tirso</option>
</select>
<span></span><br /><br />
<label><span class="text-red">* </span>Type:</label>
<input name="type" class="type" type="radio" value="direct"/>Direct
<input name="type" class="type" type="radio" value="indirect"/>Indirect
<span></span><br /><br />
<div class="input-container">
<label><span class="text-red">* </span>First Name:</label><input name="firstname" id="firstname" type="text" class="required"/><span></span><br /><br />
<label><span class="text-red">* </span>Middle Name:</label><input name="middlename" id="middlename" type="text" class="required"/><span></span><br /><br />
<label><span class="text-red">* </span>Last Name:</label><input name="lastname" id="lastname" type="text" class="required"/><span></span><br /><br />
<label><span class="text-red">* </span>Birth Day:</label><input name="bday" id="bday" type="text" class="required"/><span></span><br /><br />
<label>Tel No.:</label><input name="telno" id="telno" type="text" /><span></span><br /><br />
<label><span class="text-red">* </span>Mobile No.:</label><input name="mobileno" id="mobileno" type="text" class="required"/><span></span><br /><br />
<label><span class="text-red">* </span>Home Address:</label><input name="homeads" id="homeads" type="text" class="required"/><span></span><br /><br />
</div>
<div class="submit-container"><span class="pad-right-5"><input name="" type="submit" value="Create" class="submit-button create"/></span><input name="" type="button" value="Cancel" class="submit-button cancel-button"/></div>
</div>
</form>';
echo $html;
}
這裏提交編輯形式(不工作)
$.post("<?php echo site_url('admin/employee/edit_save') ?>",
$("#create_employee").serialize(),
function (data){
alert (data);
},'json'
)
任何建議或關於這個的想法
在此先感謝