Jquery 如何委派此活动
伙计们,我刚刚尝试委派事件,并且已经在代码的某个部分实现了,但这是我面临的一个问题,它没有以需求的方式响应,可能是因为它附加了另一个事件。 看一看-Jquery 如何委派此活动,jquery,html,delegates,event-handling,Jquery,Html,Delegates,Event Handling,伙计们,我刚刚尝试委派事件,并且已经在代码的某个部分实现了,但这是我面临的一个问题,它没有以需求的方式响应,可能是因为它附加了另一个事件。 看一看- $(document).ready(function() { $('#divGrid').on("click", ".edit_tr", function() { //$(".edit_tr").click(function() var ID=$(this).attr('id'); $("#client_"+ID).
$(document).ready(function() {
$('#divGrid').on("click", ".edit_tr", function() {
//$(".edit_tr").click(function()
var ID=$(this).attr('id');
$("#client_"+ID).hide();
$("#staff_"+ID).hide();
$("#matter_"+ID).hide();
$("#client_input_"+ID).show();
$("#staff_input_"+ID).show();
$("#matter_input_"+ID).show();
})
.change(function() {
var ID=$(this).attr('id');
var client=$("#client_input_"+ID).val();
var staff=$("#staff_input_"+ID).val();
var matter=$("#matter_input_"+ID).val();
var dataString = 'id='+ ID +'&clientname='+client+'&staff='+staff+'&matter='+matter;
if(client.length>0 && staff.length>0 && matter.length>0) {
$.ajax({
type: "POST",
url: "table_edit_ajax.php",
data: dataString,
cache: false,
success: function(html) {
$("#client_"+ID).html(client);
$("#staff_"+ID).html(staff);
$("#matter_"+ID).html(matter);
}
});
}
else {
alert('enter something');
}
});
// Edit input box click action
$(".editbox").mouseup(function() {
return false;
});
// Outside click action
$(document).mouseup(function() {
$(".editbox").hide();
$(".text").show();
});
});
这是html-
<div id="divGrid">
<table class="footable" data-filter="#filter" id="tableresult" >
<thead>
<th>Client name</th>
<th>Staff name</th>
<th>Matter</th>
<th> Delete</th>
</thead>
<tr id="<?php echo $id; ?>" class="edit_tr">
<td class="edit_td" >
<span id="client_<?php echo $id; ?>" class="text"><?php echo $clientname; ?></span>
<input type="text" value="<?php echo $clientname; ?>" class="editbox" id="client_input_<?php echo $id; ?>" />
</td>
<td class="edit_td">
<span id="staff_<?php echo $id; ?>" class="text"><?php echo $staff; ?></span>
<input type="text" value="<?php echo $staff; ?>" class="editbox" id="staff_input_<?php echo $id; ?>"/>
</td>
<td class="edit_td">
<span id="matter_<?php echo $id; ?>" class="text"><?php echo $matter; ?></span>
<input type="text" value="<?php echo $matter; ?>" class="editbox" id="matter_input_<?php echo $id; ?>"/>
</td>
</tr>
</tbody>
</table>
</div>
客户名称
职员姓名
要紧
删除
你甚至不缩进就理解代码了吗?所需的方式是什么?你的JavaScript有很多错误。请您提供一个片段,以便您可以轻松复制,我们也可以轻松更新和工作?@payal_suthar太棒了。请在上制作一个片段,确保它的工作方式与您在本地的工作方式相同,并让我们知道问题所在,我们很高兴为您解决问题。我还更新了您的代码,使其看起来清晰。@payal_suthar但您(发布的)代码有语法错误。。。