Javascript jQuery工作错误
我一直在使用ajax保存一行。为此,我在该行的鼠标上方显示编辑图标,然后使用ajax保存该行,然后用新形成的行替换该行。 问题是它不会在刚刚保存的行上再次显示编辑图标 我不知道发生了什么事 Url是 U:test@test.com P:test123 然后转到 然后将鼠标移到网格行上,尝试编辑记录两次,您将看到问题所在。 这是密码Javascript jQuery工作错误,javascript,jquery,jquery-selectors,Javascript,Jquery,Jquery Selectors,我一直在使用ajax保存一行。为此,我在该行的鼠标上方显示编辑图标,然后使用ajax保存该行,然后用新形成的行替换该行。 问题是它不会在刚刚保存的行上再次显示编辑图标 我不知道发生了什么事 Url是 U:test@test.com P:test123 然后转到 然后将鼠标移到网格行上,尝试编辑记录两次,您将看到问题所在。 这是密码 jQuery('[rel="datepicker"]').datepicker(); jQuery('[rel="innerRows"]').mo
jQuery('[rel="datepicker"]').datepicker();
jQuery('[rel="innerRows"]').mouseover(function (){
//alert('hererere');
var spanId = jQuery(this).attr('spanid');
jQuery('[rel="innerSpans"]').hide();
jQuery('#edit_'+spanId).show();
});
jQuery('[rel="editButton"]').click(function (){
var recordId = jQuery(this).attr('id');
jQuery('#show_'+recordId).hide();
jQuery('#hid_'+recordId).show();
});
jQuery('[rel="saveRecord"]').click(function (){
var recordId = jQuery(this).attr('recId');
var event = jQuery.trim(jQuery('#event_'+recordId).val());
var date = jQuery.trim(jQuery('#date_'+recordId).val());
var location = jQuery.trim(jQuery('#location_'+recordId).val());
var notes = jQuery.trim(jQuery('#notes_'+recordId).val());
if(event !='' && date !='' && location !='' && notes !=''){
jQuery.ajax({
url:'/application/saveevent/',
dataType: 'html',
data: '&recId='+recordId+'&event='+event+'&date='+date+'&location='+location+'¬es='+notes,
success : function (text){
jQuery('#hid_'+recordId).replaceWith(text);
bind();
}
});
}
function bind(){
jQuery('[rel="datepicker"]').datepicker();
jQuery('[rel="innerRows"]').mouseover(function (){
var spanId = jQuery(this).attr('spanid');
jQuery('[rel="innerSpans"]').hide();
jQuery('#edit_'+spanId).show();
});
jQuery('[rel="editButton"]').click(function (){
var recordId = jQuery(this).attr('id');
jQuery('#show_'+recordId).hide();
jQuery('#hid_'+recordId).show();
});
jQuery('[rel="saveRecord"]').click(function (){
var recordId = jQuery(this).attr('recId');
var event = jQuery.trim(jQuery('#event_'+recordId).val());
var date = jQuery.trim(jQuery('#date_'+recordId).val());
var location = jQuery.trim(jQuery('#location_'+recordId).val());
var notes = jQuery.trim(jQuery('#notes_'+recordId).val());
if(event !='' && date !='' && location !='' && notes !=''){
jQuery.ajax({
url:'/application/saveevent/',
data: '&recId='+recordId+'&event='+event+'&date='+date+'&location='+location+'¬es='+notes,
success : function (text){
jQuery('#hid_'+recordId).replaceWith(text);
bind();
}
});
}
});
}
问候
Himanshu Sharma。您需要使用未来的事件观察者。
打开
或委派
。您正在将悬停事件绑定到DOM中的所有行,但添加新行时,它尚未绑定到该事件
您需要将事件绑定到父容器,如下所示:
$('#myTable').on('hover','tr',function(){
// show icon
});
请将代码的相关部分放在此处的帖子中,以便将来的访问者即使在网站更改或离线后也能看到问题和答案。您应该使用
$
而不是jQuery
。另外,请阅读关于()事件,这样您就不需要重新绑定所有内容。@Joseph您不能告诉他使用$
而不首先知道他没有为其他内容保留$
,他可以将其交给prototype或其他框架。您看到ajax成功时调用的绑定函数了吗?它包含整个鼠标悬停事件和所有事件同样,它不应该绑定新行吗?你不能只调用bind()
,期望它知道需要绑定到哪个节点的事件:)我刚刚在那里添加了bind函数@Alien。请看一看,这既冗余又低效。相信我,你想在这里对使用。我的意思是,它对dom中新注入的行也有效吗?