使用 JQuery 插入 INPUT 字段时如何控制表格单元格宽度
我在针对 webkit 的网页上有一个就地编辑功能。 HTML 很简单。
我使用 jQuery 将单击处理程序附加到每个单元格:
$("table td").click(editMe);
function editMe(e) {
var w = $(this).width(); // returns cell width
$(this).html("<span>Foo</span"); // does not change table width
$(this).html('<input type="text" />'); // CAUSES CELL width to BLOW UP! (gets VERY wide)
var in = $('<input type="text" />');
in.width(w-10);
$(this).html(in); // CAUSES CELL WIDTH TO BLOW UP! (nearly doubles)
}
设置多少宽度似乎没有任何区别。输入没有填充或边距,没有边框。表格单元格的宽度变得疯狂。重点是 Webkit (Safari / Adobe AIR)。但为什么?
如何让输入尺寸与其要插入的表格单元格匹配?
I've got an edit in place feature on a web page that is targeted for webkit.
The HTML is trivial.
I attach a click handler to each cell with jQuery:
$("table td").click(editMe);
function editMe(e) {
var w = $(this).width(); // returns cell width
$(this).html("<span>Foo</span"); // does not change table width
$(this).html('<input type="text" />'); // CAUSES CELL width to BLOW UP! (gets VERY wide)
var in = $('<input type="text" />');
in.width(w-10);
$(this).html(in); // CAUSES CELL WIDTH TO BLOW UP! (nearly doubles)
}
No amount of setting the width seems to make ANY difference. Input has no padding, or margins, no borders. The table cell width just goes berzerk. Focus is on Webkit (Safari / Adobe AIR). But WHY?
How can I have the input dimensions MATCH the table cell it is being inserted into?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,
我没有得到确切的答案,但事实证明罪魁祸首在于960Grid CSS框架的reset.css文件中。我不知道到底是哪个设置导致了奇怪的行为,但删除该文件修复了它。
960Grid 是一个我喜欢使用的简单 CSS 框架,但是他们的 reset.css 文件中的一些内容导致我的表格崩溃了。当我删除该文件后,表的行为就如预期的那样。
Okay,
I didn't get the exact answer, but it turns out the culprit lay in the reset.css file of the 960Grid CSS Framework. I don't know exactly which setting caused the bizarre behavior, but removing that file fixed it.
960Grid is a simple CSS Framework I like to work with but something about their reset.css file caused my tables to blow up. As soon as I removed that file, the tables behaved as expected.