HTML5 <progress>
标签用于表示一个进度条,通常用于显示JavaScript中的任务进度,如文件下载进度、图片加载进度等。
属性:
max
:定义进度条的最大值。value
:定义进度条的当前值。
示例代码:
<progress value="30" max="100"> 30%</progress>
这个例子创建了一个进度条,最大值为100,当前值为30。进度条显示30%,随着value
属性的变化,进度条内部填充色也会随之变化,直至达到max
定义的值。
HTML5 <progress>
标签用于表示一个进度条,通常用于显示JavaScript中的任务进度,如文件下载进度、图片加载进度等。
属性:
max
:定义进度条的最大值。value
:定义进度条的当前值。示例代码:
<progress value="30" max="100"> 30%</progress>
这个例子创建了一个进度条,最大值为100,当前值为30。进度条显示30%,随着value
属性的变化,进度条内部填充色也会随之变化,直至达到max
定义的值。
// Base64编码
function base64Encode(str) {
return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function(match, p1) {
return String.fromCharCode('0x' + p1);
}));
}
// Base64解码
function base64Decode(str) {
return decodeURIComponent(Array.prototype.map.call(atob(str), function(c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
}
// 使用示例
var encodedStr = base64Encode('Hello, World!');
console.log(encodedStr); // 输出编码后的字符串
var decodedStr = base64Decode(encodedStr);
console.log(decodedStr); // 输出解码后的字符串
这段代码提供了Base64的编码和解码功能。base64Encode
函数接收一个字符串,将其进行URI编码,然后将编码后的字符串中的百分号编码转换为对应的字符,并使用btoa
进行Base64编码。base64Decode
函数则执行相反的操作,将Base64字符串解码并转换回原始字符串。
在uniapp中使用Leaflet加载天地图,可以通过集成Leaflet插件和天地图的方式实现。以下是一个简单的示例代码:
npm install leaflet
pages.json
中配置"web-view"
,允许在App端使用网页组件:
{
"pages": [
{
"path": "pages/index/index",
"style": {
"navigationBarTitleText": "首页",
"enableWebview": true
}
}
]
}
.vue
文件中,引入Leaflet和天地图,并初始化地图:
<template>
<view class="content">
<web-view src="/hybrid/leaflet-map.html"></web-view>
</view>
</template>
<script>
export default {
data() {
return {};
},
onReady() {
// 初始化Leaflet地图
this.initMap();
},
methods: {
initMap() {
const map = L.map('map').setView([39.916527, 116.397128], 12); // 设置中心点和缩放级别
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
// 加载天地图
const tdtLayer = L.tileLayer('https://{s}.tianditu.gov.cn/vec_c/wmts?service=wmts&request=GetTile&version=1.0.0&LAYER=vec&tileMatrixSet=c&TileMatrix={z}&TileRow={y}&TileCol={x}&style=default&format=tiles&tk=你的天地图key').addTo(map);
// 设置最大和最小缩放级别
tdtLayer.setMaxZoom(18);
tdtLayer.setMinZoom(1);
}
}
};
</script>
static
目录下创建leaflet-map.html
文件,并在其中初始化Leaflet:
<!DOCTYPE html>
<html>
<head>
<title>Leaflet Map</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css" />
<style>
#map {
height: 100%;
width: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"></script>
<script>
var map = L.map('map').setView([39.916527, 116.397128], 12);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
// 加载天地图
var tdtLayer = L.tileLayer('https://{s}.tianditu.gov.cn/vec_c/wmts?service=wmts&request=GetTile&version=1.0.0&LAYER=vec
HTML5.1中的<textarea>
和<label>
标签用于创建多行文本输入区域和定义标签关联表单元素。以下是如何使用这两个标签的示例代码:
<!DOCTYPE html>
<html>
<head>
<title>Textarea and Label Example</title>
</head>
<body>
<form action="#">
<label for="message">Message:</label>
<textarea id="message" name="message" rows="4" cols="50">
请输入您的信息...
</textarea>
<input type="submit">
</form>
</body>
</html>
在这个例子中,<label>
标签通过for
属性指定与<textarea>
的id
值相同,以此来建立两者之间的关联。用户点击<label>
时,与之关联的表单元素(在这个例子中是<textarea>
)会获得焦点。<textarea>
允许用户输入多行文本,其中rows
和cols
属性分别指定了文本区域的行数和列数。当用户输入信息后,可以通过提交表单将信息发送到服务器。
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class MyController {
@GetMapping("/greeting")
public String greeting(Model model) {
model.addAttribute("name", "World");
return "greeting";
}
}
这段代码定义了一个控制器MyController
,它处理"/greeting"的GET请求。它将一个属性"name"添加到模型中,值为"World",并返回视图名称"greeting"。这个视图应该是一个Thymeleaf模板,它可以使用${name}
来访问模型中的"name"属性。
HTML5 引入了多媒体元素,包括 video
和 audio
标签,以简化多媒体内容的嵌入。
video
) 标签HTML5 的 video
标签可以用来嵌入视频内容。
<video width="320" height="240" controls>
<source src="movie.mp4" type="video/mp4">
<source src="movie.ogg" type="video/ogg">
Your browser does not support the video tag.
</video>
width
和 height
属性用来设置视频的尺寸。controls
属性添加视频播放的默认控制界面(播放、暂停、音量控制等)。<source>
标签指定视频文件的路径和类型。video
标签,会显示 <video>
标签中的文本内容。audio
) 标签HTML5 的 audio
标签可以用来嵌入音频内容。
<audio controls>
<source src="song.mp3" type="audio/mpeg">
<source src="song.ogg" type="audio/ogg">
Your browser does not support the audio tag.
</audio>
controls
属性添加音频播放的默认控制界面(播放、暂停、音量控制等)。<source>
标签指定音频文件的路径和类型。audio
标签,会显示 <audio>
标签中的文本内容。<source>
标签提供多种格式的文件源。HTML5 的 <dialog>
标签用于创建对话框或者提示框,它可以用CSS来定制样式。
基本用法:
<dialog open>
这是一个打开的对话框。
</dialog>
<dialog>
标签默认是不可见的,需要设置 open
属性来显示它。
你可以通过 JavaScript 来控制 <dialog>
的打开和关闭:
<dialog id="myDialog">
这是一个通过 JavaScript 控制的对话框。
</dialog>
<button onclick="openDialog()">打开对话框</button>
<button onclick="closeDialog()">关闭对话框</button>
<script>
function openDialog() {
document.getElementById('myDialog').show();
}
function closeDialog() {
document.getElementById('myDialog').close();
}
</script>
<dialog>
元素还支持通过 CSS 进行样式定制,比如隐藏关闭按钮:
dialog::backdrop {
background: rgba(0, 0, 0, 0.5);
}
dialog::close-button {
display: none;
}
请注意,<dialog>
标签的兼容性在不同的浏览器中可能会有所不同,请在实际应用前检查浏览器的兼容性。
在Vue 3中,如果你想要在页面跳转后使用锚点定位,你可以通过编程式导航结合router-link
来实现。这里是一个简单的例子:
// router.js
import { createRouter, createWebHistory } from 'vue-router';
import Home from './views/Home.vue';
import About from './views/About.vue';
const router = createRouter({
history: createWebHistory(),
routes: [
{ path: '/', component: Home },
{ path: '/about', component: About },
// 其他路由...
],
});
export default router;
router-link
来定义锚点,并通过编程式导航跳转到指定锚点。
<template>
<div>
<!-- 使用 router-link 定义锚点 -->
<router-link to="/about#team">About Team</router-link>
<!-- 使用按钮触发页面跳转 -->
<button @click="goToAboutTeam">Go to About Team</button>
</div>
</template>
<script setup>
import { useRouter } from 'vue-router';
const router = useRouter();
// 编程式导航函数
function goToAboutTeam() {
// 使用编程式导航跳转到 /about 页面并定位到 team 锚点
router.push({ path: '/about', hash: '#team' });
}
</script>
在上面的例子中,我们定义了一个router-link
指向/about
页面的#team
锚点,同时我们还创建了一个按钮,当点击按钮时,会调用goToAboutTeam
函数,该函数使用router.push
方法来实现页面跳转,并定位到指定的锚点。
SVG(Scalable Vector Graphics)是一种基于XML的图像格式,可以用来创建矢量图形。它使用XML来定义图形对象,然后可以在网页上使用这些对象。
SVG的基本元素包括:
<rect>
:矩形<circle>
:圆形<ellipse>
:椭圆<line>
:线条<polyline>
:折线<polygon>
:多边形<path>
:路径下面是一个简单的SVG示例,它创建了一个红色的矩形:
<!DOCTYPE html>
<html>
<body>
<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg">
<rect x="10" y="10" width="80" height="80"
style="stroke:#ff0000; fill:none;"/>
</svg>
</body>
</html>
在这个例子中,<rect>
元素定义了一个矩形,x
和y
属性定义了矩形左上角的位置,width
和height
属性定义了矩形的尺寸。style
属性定义了矩形的颜色和填充方式。
SVG是一种强大的工具,可以用来创建各种复杂的图形和图表,并且因为它是基于XML的,所以它可以和JavaScript以及CSS紧密结合,从而实现更多的交互效果。
HTML5引入了许多新特性,包括更好的表单输入类型、地理位置API、Canvas绘图、离线应用程序缓存等。以下是一些HTML5的功能和示例代码:
if ("geolocation" in navigator) {
navigator.geolocation.getCurrentPosition(function(position) {
console.log("Latitude is :", position.coords.latitude);
console.log("Longitude is :", position.coords.longitude);
});
} else {
console.log("Geolocation is not supported by this browser.");
}
<canvas id="myCanvas" width="200" height="100"></canvas>
<script>
var canvas = document.getElementById('myCanvas');
var ctx = canvas.getContext('2d');
ctx.fillStyle = '#FF0000';
ctx.fillRect(0, 0, 150, 75);
</script>
<!-- Audio -->
<audio controls>
<source src="horse.ogg" type="audio/ogg">
<source src="horse.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<!-- Video -->
<video width="320" height="240" controls>
<source src="movie.mp4" type="video/mp4">
<source src="movie.ogg" type="video/ogg">
Your browser does not support the video tag.
</video>
<form>
Email: <input type="email" name="user_email">
URL: <input type="url" name="user_url">
Number: <input type="number" name="user_number" min="1" max="5" step="1">
Range: <input type="range" name="user_range" min="1" max="10">
Search: <input type="search" name="user_search">
<input type="submit">
</form>
<!DOCTYPE HTML>
<html manifest="example.appcache">
...
<table>
<caption>Table caption here</caption>
<thead>
<tr>
<th>Header 1</th>
<th>Header 2</th>
</tr>
</thead>
<tbody>
<tr>
<td>Row 1, Cell 1</td>
<td>Row 1, Cell 2</td>
</tr>
<tr>
<td>Row 2, Cell 1</td>
<td>Row 2, Cell 2</td>
</tr>
</tbody>
</table>
if(typeof(EventSource)!=="undefined") {
var source=new EventSource