<ul style="left: 115px; visibility: visible; display: block;"><li><a target="context" href="notes.php" onclick="parent.tab.location='hide_tab.php';parent.sub_tab.location='blank.php' ">個人備忘錄</a></li> <li><a target="tab" href="user_setting.php" onclick="parent.context.location='hide_tab.php';parent.tab.location='blank.php';parent.sub_tab.location='blank.php' ">帳戶通知管理</a></li><li><a target="context" href="change_pass.php" onclick="parent.tab.location='hide_tab.php';parent.sub_tab.location='blank.php' ">變更密碼</a></li><li><a target="tab" href="group_module_setting.php" onclick="parent.context.location='blank.php';parent.sub_tab.location='blank.php' ">分組權限設定</a></li></ul> 点击li,让上一级ul的display为none
时间: 2024-03-05 15:50:24 浏览: 162
可以使用JavaScript来实现这个功能。具体代码如下:
```
// 获取所有的li元素
var liElements = document.getElementsByTagName("li");
// 给每个li元素添加点击事件
for (var i = 0; i < liElements.length; i++) {
liElements[i].addEventListener("click", function() {
// 找到当前li元素的父级ul元素
var parentUl = this.parentNode;
// 隐藏父级ul元素
parentUl.style.display = "none";
});
}
```
这段代码会为页面中所有的li元素添加点击事件。当用户点击任意一个li元素时,它的父级ul元素将会被隐藏。
相关问题
<ul style="left: 115px; visibility: visible; display: none;"><li><a target="context" href="notes.php" onclick="parent.tab.location='hide_tab.php';parent.sub_tab.location='blank.php' ">個人備忘錄</a></li><li><a target="tab" href="user_setting.php" onclick="parent.context.location='hide_tab.php';parent.tab.location='blank.php';parent.sub_tab.location='blank.php' ">帳戶通知管理</a></li><li><a target="context" href="change_pass.php" onclick="parent.tab.location='hide_tab.php';parent.sub_tab.location='blank.php' ">變更密碼</a></li><li><a target="tab" href="group_module_setting.php" onclick="parent.context.location='blank.php';parent.sub_tab.location='blank.php' ">分組權限設定</a></li></ul>点击a,让上一级uldisplay为block
您可以使用JavaScript来实现这个功能,可以给a标签添加一个点击事件,事件中获取当前a标签的父节点ul,然后设置其display属性为block即可。
示例代码如下:
```html
<ul id="myList">
<li><a href="#" onclick="showList(this)">点击显示列表</a>
<ul style="left: 115px; visibility: visible; display: none;">
<li><a target="context" href="notes.php" onclick="parent.tab.location='hide_tab.php';parent.sub_tab.location='blank.php' ">個人備忘錄</a></li>
<li><a target="tab" href="user_setting.php" onclick="parent.context.location='hide_tab.php';parent.tab.location='blank.php';parent.sub_tab.location='blank.php' ">帳戶通知管理</a></li>
<li><a target="context" href="change_pass.php" onclick="parent.tab.location='hide_tab.php';parent.sub_tab.location='blank.php' ">變更密碼</a></li>
<li><a target="tab" href="group_module_setting.php" onclick="parent.context.location='blank.php';parent.sub_tab.location='blank.php' ">分組權限設定</a></li>
</ul>
</li>
</ul>
<script>
function showList(a) {
var ul = a.parentNode.querySelector('ul');
ul.style.display = 'block';
}
</script>
```
在这个示例中,我们给a标签添加了一个onclick事件,点击后调用showList函数。这个函数中,我们首先获取当前a标签的父节点ul,然后设置其display属性为block。这样就可以实现点击a标签显示下方的列表的功能了。
<ItemsControl x:Class="HDSProject.Control.CustomFont" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:HDSProject.Control" mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800" x:Name="itemCtrl" ItemsSource="{Binding Path=Title2, RelativeSource={RelativeSource Mode=Self}}" FontSize="20" Foreground="Teal" > <ItemsControl.ItemContainerStyle> <Style TargetType="ContentPresenter"> <Setter Property="VerticalAlignment" Value="Center" /> </Style> </ItemsControl.ItemContainerStyle> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <StackPanel Orientation="Horizontal" HorizontalAlignment="Center"/> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> <DataTemplate> <StackPanel> <Border Margin="{Binding Path=CharacterSpacing, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:CustomFont}}"> <TextBlock Text="{Binding}" /> </Border> <Rectangle Height="1" Fill="{Binding Foreground, ElementName=itemCtrl}" Margin="0,0,0,5"> <Rectangle.Style> <Style TargetType="Rectangle"> <Setter Property="Visibility" Value="Collapsed" /> <Style.Triggers> <DataTrigger Binding="{Binding ShowUnderline, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:CustomFont}}" Value="True"> <Setter Property="Visibility" Value="Visible" /> </DataTrigger> </Style.Triggers> </Style> </Rectangle.Style> </Rectangle> </StackPanel> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl>给这个自定义控件添加Thumb
要给这个自定义控件添加Thumb,可以在ItemsControl的外层包裹一个Grid,然后在Grid的右下角添加一个Thumb。以下是修改后的代码示例:
```
<Grid>
<ItemsControl x:Name="itemCtrl" ItemsSource="{Binding Path=Title2, RelativeSource={RelativeSource Mode=Self}}" FontSize="20" Foreground="Teal" >
<ItemsControl.ItemContainerStyle>
<Style TargetType="ContentPresenter">
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
</ItemsControl.ItemContainerStyle>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel>
<Border Margin="{Binding Path=CharacterSpacing, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:CustomFont}}">
<TextBlock Text="{Binding}" />
</Border>
<Rectangle Height="1" Fill="{Binding Foreground, ElementName=itemCtrl}" Margin="0,0,0,5">
<Rectangle.Style>
<Style TargetType="Rectangle">
<Setter Property="Visibility" Value="Collapsed" />
<Style.Triggers>
<DataTrigger Binding="{Binding ShowUnderline, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:CustomFont}}" Value="True">
<Setter Property="Visibility" Value="Visible" />
</DataTrigger>
</Style.Triggers>
</Style>
</Rectangle.Style>
</Rectangle>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<Thumb DragDelta="Thumb_DragDelta" Width="10" Height="10" HorizontalAlignment="Right" VerticalAlignment="Bottom" />
</Grid>
```
注意,这里我添加了一个Thumb,并且为它绑定了DragDelta事件。您需要在代码中实现Thumb_DragDelta方法,以便在Thumb被拖动时进行相应的处理。
阅读全文
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)