jQuery contentitable不工作- Internet Explorer 8 -编辑表项

jQuery contentEditable not working - Internet Explorer 8 - edit table items

本文关键字:编辑 Explorer Internet contentitable 工作 jQuery      更新时间:2023-09-26

我需要让这个代码在Internet Explorer 8中工作:

http://jsfiddle.net/tYtQV/5/

$("tbody tr td").bind("click", onClick);
function onClick(e) {
    if(e.currentTarget.contentEditable != null)
    {
            $(e.currentTarget).attr("contentEditable",true);
    }
    else
    {
            $(e.currentTarget).append("<input type='text'>");
    }
}

在Firefox或Chrome中可以正常工作,但在IE8中不行。

我尝试将bind()更改为live(),但这没有任何效果-当我单击列表项时,它只是不做任何事情(事件处理程序被调用,虽然)

如果我将contentEditable更改为全小写的" contentEditable ",它会在每次单击元素时追加文本表单,这不是我想要的。

这段代码的目的是使表项可编辑。对如何解决这个问题有什么想法吗?

提前感谢!

TD-elements不能设置为可满足内容。参考此页面:http://msdn.microsoft.com/en-us/library/ms537837(v=vs.85).aspx

您可以在单元格中添加一个空的div,并将其命名为contenteditable

在div中添加contentitable的唯一问题是占位符问题,因为该区域只能对特定区域进行编辑。如果您有一个占位符,并删除了占位符以编写更多内容,则删除了编辑功能,因此请确保处理好这一点。

IE中有很多元素是不能直接设置的。但是,您可以将整个表封装到一个内容可编辑的div中。

 <div contenteditable="true">
     <table>
       ...
    </table>
 </div>