【发布时间】:2011-12-16 12:49:11
【问题描述】:
我在一些论坛上读到,要使 html 表格看起来被禁用是添加一个 div 层。我的问题是我不知道该怎么做。
我有 3 个问题:
如何设置 div 高度,以便在添加新行时表格增加高度时自动调整为表格高度。
如何让 div 覆盖表格。我不知道如何分层 html 元素。
我将如何编写 javascript 代码,使我的表格在我单击“禁用”按钮时看起来被禁用,并在我单击“启用”按钮时再次启用它。
tabledisabletest.html
<html>
<head>
<script type="text/javascript">
</script>
<style type="text/css">
table#tblTest {
width: 100%;
margin-top: 10px;
font-family: verdana,arial,sans-serif;
font-size:12px;
color:#333333;
border-width: 1px;
border-color: #666666;
border-collapse: collapse;
}
table#tblTest tr.highlight td {
background-color: #8888ff;
}
table#tblTest tr.normal {
background-color: #ffffff;
}
table#tblTest th {
white-space: nowrap;
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #666666;
background-color: #dedede;
}
table#tblTest td {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #666666;
background-color: #ffffff;
}
#disabler {
width: 100%;
height: 200px;
background-color: #bbb;
opacity:0.6;
}
</style>
</head>
<body>
<div id="disabler"></div>
<table id="tblTest">
<thead>
<tr>
<th>Name</th>
<th>Address</th>
</tr>
</thead>
<tbody>
<tr>
<td>Tom</td>
<td>UK </td>
</tr>
<tr>
<td>Henrik</td>
<td>Denmark</td>
</tr>
<tr>
<td>Lionel</td>
<td>Italy</td>
</tr>
<tr>
<td>Ricardo</td>
<td>Brazil</td>
</tr>
<tr>
<td>Cristiano</td>
<td>Portugal</td>
</tr>
</tbody>
</table>
<input type="button" onclick="disable = true;" value="Disable" />
<input type="button" onclick="disable = false;" value="Enable" />
</body>
</html>
我有 div disabler 来禁用,但我不能让它覆盖桌子。
请帮我解决这个问题。我对这件事很陌生。
【问题讨论】:
-
建议:使用 jQuery BlockUI。演示:jquery.malsup.com/block/#demos
-
我想我需要先学习原生 javascript,然后再学习一些高级技术。我还需要学习javascript,因为我需要准备考试。
-
让它看起来被禁用到底是什么意思?用户仍然可以从中选择文本吗?它是否需要具有您在禁用控件上看到的那些边框和阴影效果?
-
是否可以禁用文本选择?我想让它看起来像一个禁用的控件。
标签: javascript css html-table