“禁用”带有 Javascript 的 HTML 表格
我最近在很多网站上都看到过这种做法,但似乎无法找到一个。本质上,我想在单击按钮时“禁用”整个面板(即 HTML 表格上的表单)。
我所说的禁用是指我不希望表格中的表单元素可用,并且我希望表格淡出。
我已经能够通过在桌子上放置一个“面纱”来实现这一点,其中带有一个绝对定位的 div,该 div 具有低不透明度的白色背景(因此您可以看到其后面的表格,但无法单击任何内容,因为 div就在它前面)。这还添加了我想要的褪色效果。但是,当我将面纱的高度设置为 100% 时,它只会达到屏幕的大小(不包括滚动),因此如果用户向上或向下滚动,他们会看到面纱的边缘,这并不漂亮。
我假设这通常是以不同的方式完成的。有没有人有一些建议作为实现这一目标的更好方法?
I've seen this done in a lot of sites recently, but can't seem to track one down. Essentially I want to "disable" an entire panel (that's in the form on an HTML table) when a button is clicked.
By disable I mean I don't want the form elements within the table to be usable and I want the table to sort of fade out.
I've been able to accomplish this by putting a "veil" over the table with an absolutely positioned div that has a white background with a low opacity (so you can see the table behind it, but can't click anything because the div is in front of it). This also adds the faded effect that I want. However, when I set the height of the veil to 100% it only goes to the size of my screen (not including the scrolling), so if a user scrolls up or down, they see the edge of the veil and that's not pretty.
I'm assuming this is typically done in a different fashion. Does anyone have some suggestions as a better way to accomplish this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
你可以尝试像这样的javascript:
You could try javascript like:
使用 Jquery 尝试以下操作
Try the below with Jquery
禁用 HTML 表格的内部元素也可以使用 指针来完成-events CSS 样式如下所示:
在 JavaScript 代码中的任何所需位置,我们可以向父表添加
disabled
属性,这将使 CSS 样式生效:Disabling the inner elements of an HTML table can also be done using pointer-events CSS style as shown below:
At any desired point in our JavaScript code, we can add
disabled
attribute to the parent table which will bring the CSS styling into effect:另一种方法是使用不透明度属性。
Another way to do it would be using the opacity property.
难道你不能用 JavaScript 找出该区域的高度(以像素为单位)吗?然后将面纱的高度设置为该数字?
我脑子里没有确切的代码,但 offsetHeight 可能可以解决问题
Can't you just find out the height of the area in pixels with JavaScript? And then set the veil's height to that number?
I don't have the exact code in my head but offsetHeight might do the trick
如果我错了,请有人纠正我,但我见过 Javascript 和一些衍生的 Javascript 库,它们有很多选项可以完成你想做的事情。我已经使用 jQuery 库做了一些类似的效果。
需要考虑的一件事是您到底想禁用什么。本质上,表不是交互式的,因此禁用表不会有太大作用。如果是您要禁用的表格内的表单元素。您可以使用 JavaScript 来完成此操作。
除了使用 JavaScript 禁用表单元素之外,您还可以使用它来更改非交互式元素的属性。
一个例子是使用 JavaScript 更改字体和边框以及表格中其他非交互式元素的颜色,以提供禁用的“外观”。当然,您仍然需要使用 JavaScript 来禁用表单元素。
Somebody please correct me if I am wrong, but I have seen Javascript and some derivate Javascript libraries that have a lot of options for accomplishing for what you would like to do. I have used the jQuery library to do some similar effects.
One thing to think about is what exactly you are trying to disable. Essentially tables are not interactive so disabling a table would not accomplish much. If it is the form elements within the table you want to disable. You can accomplish this using JavaScript.
Along with using JavaScript for disabling the form elements, you can also use it to change properties of the non interactive elements.
An example of this would be using JavaScript to change the color of the font and borders and other non interactive elements in the table to give the "look" of being disabled. Of course you still need to use JavaScript to disable the form elements.