Javascript 在“contenteditable=”上的表td上使用“Focusout”;“真的”`
我有一个表格,当用鼠标单击时,我试图将字段转换为可编辑, 但再次强调,当焦点不在时,我希望该字段转换回它自己的位置,这是没有Javascript 在“contenteditable=”上的表td上使用“Focusout”;“真的”`,javascript,jquery,html,Javascript,Jquery,Html,我有一个表格,当用鼠标单击时,我试图将字段转换为可编辑, 但再次强调,当焦点不在时,我希望该字段转换回它自己的位置,这是没有contenteditable属性的正常td 添加属性进行得很顺利,但问题出在focusout()上,它不适用于表的特定列 focusout只有在我返回并单击该列并返回到其他td时才有效。。我想在我转移到其他td后,focusout立即工作 我是否遗漏了一些内容,或者当按下可编辑列并将其调出时,我必须按照其他流程在表中设置可编辑列,使其恢复正常。调出时,需要将content
contenteditable
属性的正常td
添加属性进行得很顺利,但问题出在focusout()上,它不适用于表的特定列
focusout只有在我返回并单击该列并返回到其他td时才有效。。我想在我转移到其他td后,focusout立即工作
我是否遗漏了一些内容,或者当按下可编辑列并将其调出时,我必须按照其他流程在表中设置可编辑列,使其恢复正常。调出时,需要将contentEditable属性设置为false,并删除inputCopyCat类
$('tr.tableRow td.inner').on('click',function(e){
e.preventDefault();
e.stopImmediatePropagation();
$(this).attr('contentEditable','true');
$(this).addClass('inputCopyCat');
$(this).focusout(function(e){
// here's what you need to update in your code
$(this).attr('contentEditable','false');
$(this).removeClass('inputCopyCat');
});
console.log($(this));
});
$('tr.tableRow td.inner').focusout(function(e){
e.stopPropagation();
console.log('Hello');
});
当您移动到其他td后,希望立即切换回默认视图,那么就不用使用了
对于旧浏览器中的表,Focus将失败,而是从body或cell上的所有$cell中删除属性和类,然后为活动单元格启用该属性和类
//Now Need to Get Available Months on Based of Year
var $cell = $('tr.tableRow td.inner'),
$body = $('body');
$body.on('click',function(e){
if($cell.children(e.target).length == 0 && $cell.index(e.target) == -1){
$cell.attr('contentEditable','false')
.removeClass('inputCopyCat');
}
});
$cell.on('click',function(){
$cell.attr('contentEditable','false')
.removeClass('inputCopyCat');
$(this).attr('contentEditable','true');
$(this).addClass('inputCopyCat');
});
事实上,我缺少了。focus(),在我的功能中做了一些更新,它工作得很好。你的方法也奏效了。。但它的问题是,按下时并没有聚焦,所以我不得不点击两次来获得聚焦。但是非常感谢,谢谢。问题已经解决,您的解决方案也可以,但使用鼠标移出并不是一个好的做法,因为如果鼠标移出,td返回到正常的不可编辑位置,用户可能会感到恼火。@SizzlingCode,您提到,“我希望在移到其他td后,焦点移出立即工作”。移动到其他td意味着鼠标移动。我真的很感谢对投票人的否决票的解释。xD,我怎么知道。。您需要询问stackoverflow团队:)
//Now Need to Get Available Months on Based of Year
var $cell = $('tr.tableRow td.inner'),
$body = $('body');
$body.on('click',function(e){
if($cell.children(e.target).length == 0 && $cell.index(e.target) == -1){
$cell.attr('contentEditable','false')
.removeClass('inputCopyCat');
}
});
$cell.on('click',function(){
$cell.attr('contentEditable','false')
.removeClass('inputCopyCat');
$(this).attr('contentEditable','true');
$(this).addClass('inputCopyCat');
});