我正在用C#模拟缓存。用户输入块大小、高速缓存大小和用于在高速缓存中放置块的二进制数。
在块放置之后得到的高速缓存线将被显示在html表中,并且整个高速缓存的块排列也应该被显示。我不知道如何根据选定的块大小显示这些缓存线和缓存的排列。有什么帮助吗?
发布于 2013-04-02 00:13:19
好吧,根据我在评论中提到的,也许一个碎片整理类型的UI可能适合你的需求,这里有一个快速和肮脏的例子,如何在html和CSS中做到这一点:
<html>
<head>
<style>
.block { width:20px; height:20px; float:left; border:1px; border-color: black; border-style:solid; }
.used { background-color: green }
.expired { background-color: red }
.free { background-color: grey }
</style>
</head>
<body>
<script language="javascript">
var types = ['used', 'expired', 'free'];
var i = 0;
while (i < 256) {
var type = Math.floor(Math.random() * 3); //rnd between 0-2
var size = Math.floor(Math.random() * 20) + 1; //rnd 1-20
while(size > 0 && i < 256) {
document.write('<div class="block ' + types[type] + '"></div>');
size = size - 1;
i = i + 1;
}
}
</script>
</body>
</html>这里我只是随机生成256个块,随机使用或释放,每次最多20个块。归根结底,这只是一个用特定类生成<div>的问题,仅此而已。
它看起来像这样:

https://stackoverflow.com/questions/15738517
复制相似问题