原生引入<dialog>元素

HTML5对话框特性
本文介绍HTML5新增的&lt;dialog&gt;元素,演示如何使用原生方式创建弹窗,并探讨其与UI框架的不同之处。文章包含具体示例代码,展示了&lt;dialog&gt;元素的显示、关闭及样式设置。

  <dialog>元素是html5新推出的特性,之前我用弹框都是通过ui框架来实现,今天就试一下用原生方式引用弹框。

  首先,我们在页面上要定义<dialog></dialog>标签,然后通过modal.showModal()和modal.close()的方法来分别实现弹出框的显示和关闭功能。如果你想默认页面打开弹出框,就在dialog元素里加open即可打开,是不是觉得很简单?而且在dialog框里也可以和模态框外的元素进行交互,同时模态框在关闭的时候会传个状态码,可以通过modal.returnValue来获取,这样就实现了简单的模态框展示。如果想要设置模态框的样式,可以通过dialog元素设置css样式,dialog::backdrop设置背景样式。

  具体我自己实现的代码如下:

    

<body>
    <p class="pText">haode</p>
  <button class="btn" type="button">click</button>
  <dialog id="demo-modal">
    <h3 class="modal-header">hello!</h3>
    <div class="modal-body">
      <p class="ppText"></p>
    </div>
    <footer class="modal-footer">
      <button id="close" type="button">close</button>
    </footer>
  </dialog>
    <script src="../jquery-1.12.4.js" charset="utf-8"></script>
  <script charset="utf-8">
  $(".btn").on('click', function(event) {
    event.preventDefault();
    const modal = $("#demo-modal")[0];
    modal.showModal();
    console.log("//",$(".pText").text());
    $(".ppText").text($(".pText").text());
    $("#close").on('click', function(event) {
      event.preventDefault();
      modal.close("close");
      console.log("mm",modal.returnValue);//close
    });
  });
</script>
</body>

但是,dialog元素的兼容性还是不是很好,但在谷歌上是可以显示的,可能后续会有更多浏览器支持这个特性。

转载于:https://www.cnblogs.com/abey/p/8384108.html

<template> <div> <table border width="500" cellspacing="0"> <thead> <tr> <th>id</th> <th>姓名</th> <th>年龄</th> <th>性别</th> <th>状态</th> <th>操作</th> </tr> </thead> <tbody> <tr v-for="item in tableData" :key="item.id"> <td>{{ item.id }}</td> <td>{{ item.name }}</td> <td>{{ item.age }}</td> <td>{{ item.gender }}</td> <td>{{ item.status == 1 ? "启用":"禁用"}}</td> <td> <button @click="updataData(item)">修改</button> <button @click="changeStatus(item)">{{ item.status == 1 ? "禁用":"启用"}}</button> </td> </tr> </tbody> </table> <div v-show="flag"> 姓名:<input v-model="currentName" type="text"> <br><br> 年龄:<input v-model="currentAge" type="text"> <br><br> 性别:<select v-model="currentGender"> <option value="男">男</option> <option value="女">女</option> </select> <br><br> <button @click="saveData">确定</button> <button @click="cancelEdit">取消</button> </div> </div> </template> <script> export default{ data(){ return{ tableData:[ {id: 1,name:"张三",age:18,gender:"女",status:0}, {id: 2,name:"李四",age:30,gender:"男",status:1}, {id: 3,name:"王五",age:18,gender:"女",status:0}, {id: 4,name:"赵六",age:20,gender:"男",status:1}, {id: 5,name:"孙七",age:40,gender:"男",status:1}, ], flag:false, currentName:null, currentAge:null, currentGender: null, currentid:null, } }, methods:{ changeStatus(val){ if(val.status ==1){ val.status =0; }else{ val.status = 1 } }, updataData(val){ this.currentName = val.name; this.currentAge = val.age; this.currentId = val.id; this.flag = true; }, saveData() { const index = this.tableData.findIndex(item => item.id === this.currentId); if (index !== -1) { this.tableData[index].name = this.currentName; this.tableData[index].age = this.currentAge; this.tableData[index].gender = this.currentGender; } this.resetForm(); }, cancelEdit() { this.resetForm(); }, resetForm() { this.currentId = null; this.currentName = null; this.currentAge = null; this.currentGender = null; this.flag = false; }, }, }; </script>使用element UI美化
最新发布
08-19
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值