简体   繁体   English

Chrome / IE表格单元格定位帮助

[英]Chrome/IE table cell positioning help

I am making a tiny script to make a HTML element editable. 我正在制作一个小的脚本,以使HTML元素可编辑。 When you click on an element, it gets replaced with a textarea, and you can basically enter the new text. 当您单击某个元素时,它会被文本区域替换,您基本上可以输入新文本。 When you press enter, the textarea is replaced with the original element with its innerHTML updated. 当您按Enter键时,文本区域将替换为原始元素,并更新了innerHTML。

The demo of the script is here: http://iambot.net/demo/editable/ 脚本的演示在这里: http : //iambot.net/demo/editable/

Now the problem is with the inline table editing. 现在问题是内联表编辑。 It works perfectly on FF 3.6, but on Chrome/Safari, once the value of a cell is updated, the position of the updated cell shifts to the right by the width of a cell.(Just try the demo in Chrome/Safari) It totally messes up the whole table. 它可以在FF 3.6上完美运行,但在Chrome / Safari上,一旦更新了单元格的值,更新后的单元格的位置就会向右移动一个单元格的宽度。(请尝试在Chrome / Safari中进行演示)完全弄乱了整个桌子。 I am a beginner in CSS and not able to identify where exactly I'm going wrong. 我是CSS的初学者,无法确定我到底在哪里出错。

Any help/pointers appreciated! 任何帮助/指针表示赞赏! Thanks. 谢谢。

I believe it may have to do with replacing a table cell with a textarea, which have very different display behaviors. 我认为这可能与用文本区域替换具有不同显示行为的表格单元格有关。 It may also have something to do with the variable width of the <table> element. 它也可能与<table>元素的可变宽度有关。 However, for simplicity's sake, I wanted to try to see if it could be simplified to remove the cloneNode() of _oldChild . 但是,为了简单起见,我想尝试看看是否可以简化删除cloneNode()_oldChild

I modified your code a bit and posted it here: 我对您的代码做了一些修改,并将其发布在这里:

editable.js: http://pastie.textmate.org/private/u4nruhu9pzgjjv5kwigo3q editable.js: http//pastie.textmate.org/private/u4nruhu9pzgjjv5kwigo3q

editable.html: http://pastie.textmate.org/private/hdpib2ksrllotmqi3gzkia editable.html: http//pastie.textmate.org/private/hdpib2ksrllotmqi3gzkia

It works for me now in Chrome and Firefox, but you may still want to tweak things a bit. 现在,它在Chrome和Firefox中对我有效,但是您可能仍需要进行一些调整。 Basically I just changed it to save the .innerHTML value of _child , empty the contents of _child and place the <textarea> ( _node ) as a child of _child . 基本上我只是改变它保存.innerHTML的值_child ,空的内容_child并放置<textarea>_node )作为的子_child When restoring the view, I just remove _node from the DOM and restore the contents of _child . 还原视图时,我只是从DOM中删除_node并还原_child的内容。

I hope this helps. 我希望这有帮助。 Ask away if you have any questions. 询问是否有任何疑问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM