前端基础(7):html语法(6):<a>、<dir>

本文介绍了HTML中的两个常用标签:&lt;a&gt; 和 &lt;dir&gt; 的定义及用法。&lt;a&gt; 标签用于创建超链接,&lt;dir&gt; 标签则用于定义目录列表。

2018/1/5

     复习几个html常用的标签:

(1)<a>

定义和用法

<a> 标签定义超链接,用于从一张页面链接到另一张页面。

<a> 元素最重要的属性是 href 属性,它指示链接的目标。

在所有浏览器中,链接的默认外观是:

  • 未被访问的链接带有下划线而且是蓝色的
  • 已被访问的链接带有下划线而且是紫色的
  • 活动链接带有下划线而且是红色的

提示:您可能已经注意到了,W3School 站点内的链接外观与默认的链接外观非常不同。您可以使用 CSS 伪类 向文本超链接添加复杂而多样的样式。

eg:
<a href="http://www.w3school.com.cn">W3School</a>


(2)<dir >

HTML <dir> 标签

不赞成使用 dir 元素!<dir> 标签定义目录列表。

eg:

<dir>
   <li>HTML</li>
   <li>XHTML</li>
   <li>CSS</li>
</dir>

在 HTML 4.01 中,dir 元素不被赞成使用。

在 XHTML 1.0 Strict DTD 中,dir 元素不被支持。

提示和注释:

提示:请使用 CSS 来为列表添加样式!在我们的 CSS 教程中,您可以找到更多有关为列表添加样式的细节。


<!DOCTYPE html> <html lang="zh-CN" xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"> <title>文件管理 - Hadoop-JavaEE</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> </head> <body> <div class="container mt-3"> <h2>文件管理 <small class="text-muted" id="currentPathDisplay">/</small> </h2> <hr> <!-- 消息显示:基于URL参数,增加默认文本 --> <div th:if="${param.success}" class="alert alert-success" th:text="${param.success ?: '操作成功'}"></div> <div th:if="${param.error}" class="alert alert-danger" th:text="${param.error ?: '操作失败'}"></div> <!-- 创建目录:表单action改为Thymeleaf语法 --> <div class="card mb-3"> <div class="card-body"> <h5 class="card-title">创建目录</h5> <form method="post" th:action="@{/file/mkdir}"> <div class="input-group"> <input type="text" name="path" class="form-control" placeholder="例如:/testDir"> <button type="submit" class="btn btn-primary">创建</button> </div> </form> </div> </div> <!-- 上传文件:修复隐藏域的路径传递 + 表单action --> <div class="card mb-3"> <div class="card-body"> <h5 class="card-title">上传文件</h5> <form method="post" th:action="@{/file/upload}" enctype="multipart/form-data"> <div class="input-group"> <input type="file" name="file" class="form-control" required> <input type="hidden" name="hdfsDir" id="hdfsDir" value="/"> <button type="submit" class="btn btn-success">上传</button> </div> </form> </div> </div> <!-- 文件列表:修复fileList空值 + file变量解析 + 链接参数 --> <div class="card"> <div class="card-body"> <h5 class="card-title">文件列表</h5> <table class="table table-striped"> <thead> <tr> <th>文件名</th> <th>操作</th> </tr> </thead> <tbody> <!-- 给fileList加空列表兜底,消除未定义提示 --> <tr th:each="file : ${fileList ?: #lists.emptyList()}"> <td th:text="${file ?: '未知文件'}">文件名</td> <td> <!-- 使用Thymeleaf参数语法拼接路径,避免字符串拼接错误 --> <a th:href="@{/file/download(path=/${'/' + file})}" class="btn btn-sm btn-info">下载</a> <a th:href="@{/file/delete(path=/${'/' + file})}" class="btn btn-sm btn-danger" onclick="return confirm('确定删除?')">删除</a> </td> </tr> <!-- 空列表判断:覆盖fileList为null/空的场景 --> <tr th:if="${#lists.isEmpty(fileList ?: #lists.emptyList())}"> <td colspan="2" class="text-center text-muted">暂无文件</td> </tr> </tbody> </table> </div> </div> <div class="mt-3"> <!-- 返回首页改为Thymeleaf语法 --> <a th:href="@{/}" class="btn btn-secondary">返回首页</a> </div> </div> <script> // 使用JavaScript处理路径显示 document.addEventListener('DOMContentLoaded', function() { const urlParams = new URLSearchParams(window.location.search); const path = urlParams.get('path'); if (path) { document.getElementById('currentPathDisplay').textContent = path; } // 更新隐藏字段 const hdfsDirInput = document.getElementById('hdfsDir'); hdfsDirInput.value = path || '/'; }); </script> </body> </html>对该代码错误的地方进行调整
最新发布
11-28
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

后台技术汇

对你的帮助,是对我的最好鼓励。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值