- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
好的,我有一组用于选择条件的复选框。为了便于讨论,我们假设数据如下所示:
[] Vehicles
[] Unpowered
[] Bicycle
[] Skateboard
[] Powered
[] Two-wheeled
[] Motorcycle
[] Scooter
[] Four-wheeled
etc
[] 代表复选框。
忽略这个例子明显做作的本质,想法是这样的:
现在,通过 onclick 在 block 和 none 之间切换 display CSS 属性,设置起来相对容易。
目前在页面上的结构如下:
<table>
<tr>
<td><input type="checkbox" onclick="toggle('__Vehicles');"></td>
<td>Vehicles
<table id="__Vehicles">
<tr>
<td><input type="checkbox"></td>
<td>Unpowered
etc
我应该在有人问之前指出:复选框放在表格单元格中的原因是为了控制格式。这使得有效缩进变得容易,因为下一个表格单元格中的所有内容都会对齐。
一切正常,但表格嵌套变得很深。我一直认为必须有比这更好的方法。它必须能够轻松地动态构建,并且对“树”的格式具有良好的跨浏览器支持。
我还应该提到 jQuery 是可用的。我正在用它做其他事情。
建议?
编辑:是的,复选框样式很重要,正如一些评论所指出的那样。此外,我已经根据我得到的回复发布了一个解决方案,作为下面的答案(太大而无法在此处添加),仅供那些好奇地查看示例的人使用。
最佳答案
<ul>
<li><input type="checkbox" />Vehicles <ul>
<li><input type="checkbox" />Unpowered</li>
<li><input type="checkbox" />Bicycle</li>
<li><input type="checkbox" />Skateboard</li>
</ul></li>
<li><input type="checkbox" />Powered <ul>
<li><input type="checkbox" />Two-wheeled <ul>
<li><input type="checkbox" />Motorcycle</li>
<li><input type="checkbox" />Scooter</li>
</ul></li>
<li><input type="checkbox" />Four-wheeled</li>
</ul></li>
</ul>
编辑:一些 css 和 js 来显示和隐藏嵌套元素(无复选框)
li.opened ul {
display: block;
}
li.closed ul {
display: none;
}
和 js...
$(document).ready(function() {
$('li input:checkbox').click(function () {
$(this).parent().toggleClass('opened');
$(this).parent().toggleClass('closed');
});
$('li').addClass('closed');
});
再次编辑,因为 Sparr 想要一些更好的样式(假设复选框的样式为“checkbox”
li input.checkbox { /* input:checkbox is not 100% compatible */
width: 6px;
margin: 0 2px;
/* This makes 10px be the total "width" ofh the checkbox */
}
ul {
margin: 0 0 0 10px; /* Or whatever your total checkbox width is */
padding: 0;
}
li {
padding: 0;
}
关于javascript - HTML/CSS : what's a better option for layout of a tree of nested elements than nested tables?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/485573/
我不确定是否理解好几个 Android /res/layout 文件夹所起的作用。 layout:一般布局 layout-port:必须更改为纵向的小部件布局 layout-land:小部件的布局,必
我在 Qt 4.7 中有一个界面,但我很难按照自己的意愿行事。 所需行为的基本描述:用户在组合框中进行选择,这会导致查询转到另一个函数,该函数返回一个 QHBoxLayout 对象,该对象通常包括多个
我在 res 文件夹中创建了 layout-large、layout-normal 和 layout-xlarge 并且我将所有 xml 文件复制到那些布局文件夹中 首先,我想问一下 layout(d
如图所示。我想在布局上方显示星图。我是这种编码的新手。 我的查询是1)是否可以在我的布局端显示星标(图像)? 2) 如果每次点击我的 Activity 时我都想显示星标并显示第二张图片,这可能吗?意味
关闭。这个问题需要debugging details .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 上个月关闭。 Improve this questio
我正在使用 android studio 中的 Material 设计为 pre lollipop 设备创建一个 android 应用程序,我是 android studio 的新手我正在我的项目中创
我对 Android 布局设计感到困惑。我想实现下图中的布局: 但是下面的代码产生了类似这张图片的东西: 我的代码
如果我有: Some Element.... Other Element
我有一个单元格(称为A),它在更高层次的单元格(称为P)中使用一次。当我将 A 放在 P 中时,它的边框比 A 的实际内容大得多。当我下降到 A 并进行缩放时,它被缩小了,表明边缘存在一些东西。 我可
我有一个“auth-redirect”模块,位于所有页面布局文件(1column、2column 等)的开头。这可以确保在渲染任何页面之前,如果用户未经过正确身份验证,则会重定向到登录页面。 我允许呈
我的app只支持landscape模式(这是业务需求)。 我在 layout-land 文件夹中有一个布局 xml 文件,但我没有费心创建一个 layout 文件夹,因为我在 Android list
我正在尝试为我的 Android 应用程序创建启动屏幕,如链接 http://developer.xamarin.com/guides/android/user_interface/creating_
我目前正在开发一个应用程序,我正在使用 swdp为了创建对多个屏幕的支持。 我添加了 sw400dp文件夹,根据 Android Studio 的 XML 渲染器,它基本上包含所有较小的手机。 这意味
Android 在“layout-normal”和“layout”文件夹中处理布局的方式有什么不同吗?如果我有一个被认为布局很小的设备,如果只有这两个选项,它会查看哪个文件夹? 最佳答案 是的,在您给
我已经看到了在单个页面上创建多个强制布局的解决方案,其中每个布局都包含在其自己的SVG中。但是,我一直无法找到有关如何在单个SVG中包括多个力布局的帮助。每个布局都有自己的数据与之关联。 可以在htt
我听说 Constraint-Layout 中的指南和 RTL 存在一些错误。但是这些方法都没有帮助我。我的BottomNavigation 的两边都有指南,一切都在LTR 中工作,但在RTL 中,其
我有以下渲染函数: render() { return ( Header
我知道如何使用以下文件夹,但例如我不知道 layout-small 和 layout-sw320dp 有什么区别? 此外,建议我哪些文件夹对优化很重要。我不喜欢我的程序被用户视为不规则。我希望得到您的
layout-latest.js ui-layout-west 面板 west: { paneSelector: ".ui-layout-west"
我是 Android 开发的新手,对我来说,了解图形布局和 xml 如何相互关联的一个好方法是尝试 xml 属性并查看图形 UI 中的变化。有没有一种方法可以同时并排查看,而不必从一个切换到另一个?图
我是一名优秀的程序员,十分优秀!