jquery在动态添加表时防止自动修剪
我使用 jquery 动态添加表,并使用此模式:
var tbl = $("<table></table>").addClass("messageTable");
var tblRow = $("<tr></tr>").addClass("messageRow").appendTo(tbl);
var tblCol1 = $("<td></td>").text(username+":").addClass("sender").appendTo(tblRow);
var tblCol2 = $("<td></td>").text(message).css({"color":color}).appendTo(tblRow);
当我的“message”值以所有空格开头时,看起来此机制会自动修剪文本。我确定,因为我在创建新表之前会发出警报消息
: 消息='xxx' then table column= 'xxx'
你能帮我看看如何防止自动修剪吗?
谢谢
I use jquery for adding table dynamically and I use this pattern:
var tbl = $("<table></table>").addClass("messageTable");
var tblRow = $("<tr></tr>").addClass("messageRow").appendTo(tbl);
var tblCol1 = $("<td></td>").text(username+":").addClass("sender").appendTo(tblRow);
var tblCol2 = $("<td></td>").text(message).css({"color":color}).appendTo(tblRow);
When I have 'message' value starts with all spaces, then it looks like this mechanism automatically trims the text. I am sure because I am alerting message before create new table
Ex:
message=' xxx'
then table column= 'xxx'
Can you help me how can I prevent auto trimming?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这不是自动修剪,只是 td 内的任何空格都会被忽略。尝试下面的 CSS,它应该可以工作,
DEMO 在这里
It is not the auto trimming, It is just that any space inside td will be ignored. Try the below CSS and it should work,
DEMO here