HTML基础(四):注释、URL参数、访问路径、图片地图

本文详细介绍了网页中iframe的灵活应用、URL参数的查询方式、路径的绝对与相对概念,以及如何利用图片地图实现高效导航。通过实例解析,帮助读者理解并掌握这些关键的网页技术。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、注释:<!- -内容- ->

<body>
    <iframe src="http://www.sina.com.cn" height="300" width="800" scrolling="auto">
    本页面使用框技术
    </iframe>
    <!--iframe比frameset更加灵活,frameset需要使用一个页面来作为基础,iframe在任何页面都使用框技术--> 
</body>

2、URL参数:

<body>
    <form action="list.php" method="get">
    输入查询文章ID:<input type="text" name="id" />
    <input type="submit" value="提交" />
    </form>
</body>
image

3、访问路径

绝对路径:是从盘符开始的路径,形如C:\windows\system32\cmd.exe
相对路径:是从当前路径开始的路径,假如当前路径为C:\windows,要描述上述路径,只需输入system32\cmd.exe
根路径:最高地址。----> /image/a.png  “/”根路径
4、图片地图
<body>
    <img src="bigbang.jpg" usemap="#Map" border="0" />
    <map name="Map" id="Map">
        <area shape="rect" coords="4,20,266,309" href="http://www.baidu.com" target="_blank" alt="百度" />
        <area shape="circle" coords="385,132,103" href="http://www.csdn.com" target="_blank" alt="csdn" />
        <area shape="poly" coords="765,52,656,93,659,199,824,213,874,151,765,52" href="http://www.sina.com" target="_blank" alt="新浪" /> 
</map>
</body>

image

点击相应的区域就可以去不同的网站。

---->可以使用工具来快捷使用图片地图:

image

5、文档描点

<body>
    <h1><a name="top"></a>我是开头</h1>
    <div style="height:800px;"></div>
    <a href="#top">返回开头</a>
</body>
点击“返回开头”可以跳到最上面。
<!-- static/map.html --> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1.0"> <title>高德地图</title> <script src="https://webapi.amap.com/loader.js"></script> <script src="https://cdn.bootcss.com/vue/2.6.11/vue.js"></script> <style> #map-container { width: 100%; height: 584px; border-radius: 22px; z-index: 4; } </style> </head> <body> <div id="map-container"></div> <script type="text/javascript"> window._AMapSecurityConfig = { securityJsCode: 'cf331d54f67e306ca5c0b17f7122d559' }; </script> <script src="https://webapi.amap.com/maps?v=2.0&key=f3323c24769b10828db07f07c0fcec0d&plugin=AMap.MarkerCluster"> </script> <script> // 解析URL参数 const params = new URLSearchParams(location.search); const points = JSON.parse(params.get('points')); const markers = JSON.parse(params.get('markers')); // 初始化地图 const map = new AMap.Map('map-container', { zoom: 10, center: [points[0].lng, points[0].lat], pitch: 45, showBuildingBlock: true }); markers.forEach(marker => { new AMap.Marker({ position: [marker.lng, marker.lat], title: marker.title, map: map }).on('click', () => { // 向UniApp发送点击事件 window.parent.postMessage({ type: 'markerClick', title: marker.title }, '*'); }); }); //构建带标题的HTML内容 markers.forEach(marker => { // 构建HTML内容(包含图片和标题) const content = ` <div style="position:relative; text-align:center;"> <img src="/static/images/flag.png" style="width:40px; height:50px; display:block;"> <div style="position:absolute; bottom:-90%; left:0%; transform:translateX(-50%); background: linear-gradient(180deg, rgba(227, 57, 59, 0.2) 0%, rgba(244, 124, 88, 0.2) 100%); padding:6px 0; border-radius: 18px; white-space:wrap; font-family:ShuHuiTi; font-size: 12px;font-weight: bold; margin-top:5px;border: 2px solid #F47C58;color:#E4393C;width:80px;"> ${marker.title} </div> </div> `; const markerObj = new AMap.Marker({ position: [marker.lng, marker.lat], content: content, // 使用HTML内容 anchor: 'bottom-center', // 锚点在底部中心 offset: new AMap.Pixel(0, -25) // 向上偏移 }); markerObj.on('click', () => { console.log(marker, '111'); // 将数据转为字符串 const message = JSON.stringify({ type: 'markerClick', title: marker.title }); window.parent.postMessage(message, '*'); }); map.add(markerObj); }); // 准备聚合数据 const clusterPoints = markers.map(marker => ({ lnglat: [marker.lng, marker.lat], title: marker.title, originalData: marker // 保留原始数据 })); // 点聚合初始化函数 function initCluster() { const cluster = new AMap.MarkerCluster(map, clusterPoints, { gridSize: 80, maxZoom: 15, minClusterSize: 2, renderClusterMarker: function(context) { const count = context.count; // 根据聚合点数量计算大小 const div = document.createElement('div'); div.className = 'cluster-marker'; div.style.backgroundColor = 'rgba(255,153,0,0.6)'; div.style.border = '1px solid rgba(255,153,0,1)'; div.style.borderRadius = '50%'; div.style.color = '#fff'; div.style.textAlign = 'center'; div.style.lineHeight = '40px'; div.style.width = '40px'; div.style.height = '40px'; div.innerHTML = count; return div; }, // 1. 添加标记点 renderMarker: function(context) { const markerData = context.data[0].originalData; // console.log('markerData.title', markerData.title); const content = ` <div style="position:relative; text-align:center;"> <img src="/static/images/flag.png" style="width:40px; height:50px; display:block;"> <div style="position:absolute; bottom:-90%; left:50%; transform:translateX(-50%); background: linear-gradient(180deg, rgba(227, 57, 59, 0.2) 0%, rgba(244, 124, 88, 0.2) 100%); padding:6px 0; border-radius: 18px; white-space:nowrap; font-family:ShuHuiTi; font-size: 12px; font-weight: bold; margin-top:5px; border: 2px solid #F47C58; color:#E4393C; width:80px;"> ${markerData.title} </div> </div> `; // console.log('markerDatat', markerData); const markerObj = new AMap.Marker({ position: [markerData.lng, markerData.lat], content: content, anchor: 'bottom-center', offset: new AMap.Pixel(0, -25) }); markerObj.on('click', function() { window.parent.postMessage({ type: 'markerClick', title: markerData.title }, '*'); }); return markerObj; } }); } // 加载点聚合插件 AMap.plugin('AMap.MarkerCluster', function() { initCluster(); // 插件加载完成后执行初始化 }); // 2. 绘制路线 const path = points.map(p => [p.lng, p.lat]); new AMap.Polyline({ path: path, strokeColor: "#3366FF", strokeWeight: 5, map: map }); // 3. 添加起点终点标记 points.forEach((point, i) => { new AMap.Marker({ position: [point.lng, point.lat], content: `<div class="point-label">${i === 0 ? '起' : '终'}</div>`, offset: new AMap.Pixel(-10, -10), map: map }); }); // 4. 绘制驾车路径(如果需要,可以注释掉直线路径,保留驾车路径) // 注意:这里同时绘制了直线和驾车路径,可能会重叠 if (points.length >= 2) { AMap.plugin('AMap.Driving', () => { const driving = new AMap.Driving({ map: map, // 这样驾车路线会直接显示在地图上 policy: AMap.DrivingPolicy.LEAST_TIME }); driving.search( [points[0].lng, points[0].lat], [points[points.length - 1].lng, points[points.length - 1].lat], (status, result) => { // 可以根据结果处理 } ); }); } </script> </body> </html>uniapp的vue2项目使用webview嵌套高德地图地图聚合点无法正常显示,都是只有默认图标,还有地图点击事件,无法正常回传给 <view class="description-card"> <web-view :src="mapUrl" @message="handleMessage"></web-view> </view>// 接收WebView消息 handleMessage(e) { console.log(e, '点击了标记点'); // e.detail.data 是一个数组,数组的每个元素是H5发送的消息(字符串) const [message] = e.detail.data; try { const data = JSON.parse(message); if (data.type === 'markerClick') { // 处理标记点击 } } catch (e) { console.error('解析消息失败', e); } },
最新发布
08-07
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值