data-mid html5
时间: 2023-09-06 16:03:37 浏览: 62
data-mid是一个HTML5属性,用于在标记中存储自定义的数据。它允许开发者在HTML元素中添加自定义数据,这些数据可以作为元素的属性进行访问和操作。
在HTML5之前,开发者通常使用class或id等属性来标识和存储元素的数据。但是这些属性的含义是固定的,不能灵活自定义。而data-mid属性的出现,解决了这个问题。
通过在HTML元素上添加data-mid属性,开发者可以自由定义用于存储数据的命名空间和值。这些数据可以是任何类型的,比如字符串、数字、布尔值等。这样,开发者可以根据具体的需求在HTML标记中添加自定义数据,实现更灵活的编程。
使用data-mid属性的方法很简单。只需要在HTML元素中添加data-mid属性,然后赋予它一个具体的值即可。在JavaScript中,可以通过element.dataset.mid(element为HTML元素对象)来读取和修改这个属性的值。
总结来说,data-mid是HTML5中的一个特性,用于存储自定义数据。开发者可以通过该属性在HTML标记中添加任意类型的数据,实现更灵活的编程和交互效果。
相关问题
import requests import openpyxl from bs4 import BeautifulSoup headers = { 'User-Agent':'Mozilla / 5.0(Windows NT 10.0;Win64;x64) AppleWebKit / 537.36(KHTML, likeGecko) Chrome / 114.0.0.0Safari / 537.36' } def send_requests(): url = 'https://www.qidian.com/rank/yuepiao/' resp = requests.get(url,headers=headers,proxies={'HTTP':'114.231.82.96'}) return resp.text def parase_html(data): bs = BeautifulSoup(data,'lxml') tatol_books = bs.find('div',class_='book-img-text') books = tatol_books.find_all('li') # print(books) for item in books: book1_url = item.find('div',class_='book-mid-info')('h2') book_url = book1_url.find('a') print(book_url) def start(): result = send_requests() parase_html(result) if __name__ == '__main__': start(),为什么这段代码报错?错在什么地方?请详细说明;改如何改正这代码
这段代码报错是因为在 `parase_html` 函数中,第 14 行的 `book1_url` 变量获取的是一个列表,而不是一个 BeautifulSoup 对象,所以在接下来的一行中,使用 `find` 方法会报错。
要改正这段代码,可以将第 14 行的 `book1_url` 改为 `book_mid_info`,即:
```
book_mid_info = item.find('div',class_='book-mid-info')
book_url = book_mid_info.find('h2').find('a')
```
这样就可以正确获取书籍的链接了。
根据以下代码 写一个编辑功能 layui.use(['form', 'table'], function () { var $ = layui.jquery, form = layui.form, table = layui.table; table.render({ cellHeight: 300, elem: '#demo', method: 'post', url: "{:url('/manage/aboutuslist/aboutuslist/index')}", toolbar: '#toolbarDemo', defaultToolbar: ['filter', 'exports', 'print', { title: '提示', layEvent: 'LAYTABLE_TIPS', icon: 'layui-icon-tips' }], cols: [ [{ type: "checkbox", width: 50 }, { field: 'id', width: 100, title: 'ID', unresize: true, sort: true }, { field: 'img_url', width: 400, title: '图片', templet: '<div> <img class="bianping" src="{{d.img_url}}"/></div>' }, { field: 'typeId', width: 150, title: '位置' }, { field: 'title', width: 180, title: '标题' }, { field: 'addtime', width: 180, title: '添加时间', templet: function (d) { return layui.util.toDateString(d.addtime * 1000, "yyyy-MM-dd HH:mm") } }, { fixed: 'right', title: '操作', toolbar: '#barOp', width: "16%" } ] ], limits: [5, 10, 15, 20, 50, 100], limit: 5, first: "首页", last: "尾页", page: true, skin: 'line', }); table.on('tool(tab)', function (obj) { var data = obj.data.id; var mid = obj.id; parent.layer.open({ type: 2, title: '新增信息', amin: 4, shadeClose: true, shade: 0.8, area: ['53%', '60%'], content: "{:url('/manage/aboutuslist/aboutuslist/edit/id" + mid + "')}", end: function () { $(".layui-laypage-btn").click(); } }); }); });
根据代码,这是一个使用layui框架搭建的表格,其中包含了一个编辑功能。具体步骤如下:
1. 在cols中添加一个操作列,设置fixed属性为right,width属性为固定值,比如"16%",并在该列中添加一个编辑按钮,设置toolbar属性为"#barOp",如下所示:
```
cols: [
[
{ type: "checkbox", width: 50 },
{ field: 'id', width: 100, title: 'ID', unresize: true, sort: true },
{ field: 'img_url', width: 400, title: '图片', templet: '<div> <img class="bianping" src="{{d.img_url}}"/></div>' },
{ field: 'typeId', width: 150, title: '位置' },
{ field: 'title', width: 180, title: '标题' },
{ field: 'addtime', width: 180, title: '添加时间', templet: function (d) { return layui.util.toDateString(d.addtime * 1000, "yyyy-MM-dd HH:mm") } },
{ fixed: 'right', title: '操作', toolbar: '#barOp', width: "16%" }
]
]
```
2. 在页面中添加一个编辑工具条,设置id属性为"barOp",如下所示:
```
<script type="text/html" id="barOp">
<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
</script>
```
3. 在table.on('tool')事件中添加编辑功能的实现代码,在该事件中判断如果点击的是编辑按钮,则通过obj.data.id获取当前行的id,然后弹出一个编辑页面,如下所示:
```
table.on('tool(tab)', function (obj) {
var data = obj.data;
if (obj.event === 'edit') {
var mid = data.id;
parent.layer.open({
type: 2,
title: '编辑信息',
amin: 4,
shadeClose: true,
shade: 0.8,
area: ['53%', '60%'],
content: "{:url('/manage/aboutuslist/aboutuslist/edit/id" + mid + "')}",
end: function () {
$(".layui-laypage-btn").click();
}
});
}
});
```
4. 在编辑页面中实现编辑功能。具体实现方式因具体情况而异,这里不再赘述。
综上所述,根据以上代码,可以实现一个编辑功能。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.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)
![](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)
![](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)
![](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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)