[英]How to remove spaces between table cells
正如您在两个单元格之间的表格的第二行下看到的那样,有一个我想删除的空间,但我不知道如何实现这一点。
任何帮助或建议将不胜感激。谢谢
var str1 = "78896541230"; str1 = str1.replace(/.(?=.{4})/g, 'x'); document.getElementById('output').innerHTML = str1;
<table border="0" cellspacing="0" cellpadding="1" class="formtable"> <caption>Just for fun</caption> <tr> <td>The following will contain masked input number </td> <td id="output"></td> </tr> <tr> <td> If it is not masked number, then something is wrong.</td> </tr> </table>
<table border="0" cellspacing="0" cellpadding="1" class="formtable">
<tr>
<td>The following will contain masked input number </td>
<td id="output">XXXXXXX0230</td>
</tr>
<tr>
<td colspan="2"> If it is not masked number, then something is wrong.</td>
</tr>
</table>
文本和“输出”数字之间的空白是由第二行中较长的文本引起的。 这会导致第一行的第一列拉伸。 您还嵌套了不应嵌套的<tr>
元素。
您可以将colspan="2"
添加到第二行的<td>
中。
您可以使用 html 5 中的单元格间距和单元格填充属性,并将它们的值设置为 0 或 -1
除非第二个<td>
元素中的文本增加,否则上述答案都很好。我找到了一个更好的解决方案,它确实适用于我的情况。 而不是将#output
的值放在另一个<td>
中,我可以将其内联在前一个<td>
中,这样空间就不会存在。 就是这样
Code
var str1 = "78896541230"; str1 = str1.replace(/.(?=.{4})/g, 'x'); document.getElementById('output').innerHTML = str1;
<table border="0" cellspacing="0" cellpadding="1" class="formtable"> <caption>Just for fun</caption> <tr> <td>The following will contain masked input number <strong id="output"></strong></td> </tr> <tr> <td> If it is not masked number, then something is wrong.</td> </tr> </table>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.