所以,我读了一篇关于字符集的文章,决定写一个脚本来显示ascii字符及其值。下面是我想出的代码:实际上,我是从我在这里看到的一个例子中得到的。
$(document).ready(function(){
var tbl = $("<table>");
for (var i = 0; i < 128/32; i++) {
var nextrow =$("<tr>");
$(tbl).append(nextrow);
var nextitem = 32*i;
for(var j = 0; j < 32 && nextitem + j < 128; j++){
var nextcell = $("<td>");
$(nextcell).html(nextitem+j + ":" +String.fromCharCode(nextitem + j));
$(nextrow).append(nextcell);
}
}
$("body").append(tbl);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
</body>
但是,结果是水平显示(0..31),而不是垂直显示。我想知道如何使它显示vertically...that是,将前32个字符放在一列中,然后再将下32个字符放在另一列中等等。
更重要的是,有没有更好的方法来做到这一点,而不用表格呢?谢谢。
发布于 2016-03-19 08:51:40
可能是这样的:
$(document).ready(function(){
for (var i = 0; i < 4; i++) {
var nextcol =$("<div class=\"col\">");
$("body").append(nextcol);
var nextitem = 32*i;
for(var j = 0; j < 32; j++){
var nextcell = $("<div>");
$(nextcell).html(nextitem+j + ":" +String.fromCharCode(nextitem + j));
$(nextcol).append(nextcell);
}
}
});
.col {
display: inline-block;
}
.col > div {
display: block;
padding: 10px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
</body>
https://stackoverflow.com/questions/36099093
复制相似问题