h5 使用原生JS获取富文本标签内容,并进行展示

6 篇文章 0 订阅

初衷嵌入app的h5免责声明(动态更改)

1.cdn vue做了h5,后发生点击失效,及加载vuejs慢,页面不出来
2.只能用原生js写一个小html了,获取某个元素,并在元素里添加富文本标签

document.getElementById('message').insertAdjacentHTML("afterEnd",msg),

```html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta name="viewport" charset="UTF-8" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <title>Title</title>
    <style type="text/css">
body{
    margin: 0;
}
        .msg {
            position: relative;
            width: 100%;
            /* height: 200px; */
            background-color: white;
            border-radius: 4px;
            /*position: absolute;*/
            left: 0;
            right: 0;
            top: 0;
            /* padding-top: 20px; */
            text-align: center;
            /*margin: 20% 6%;*/
            /*z-index: 999;*/
            /*display: none;*/
        }
    </style>
</head>
<body>
 <div id="app">
     <!--点击遮罩层-->
     <div  class="msg" >

             <div style="position: fixed;width:100%;height: 40px; line-height: 40px; text-align: center; top: 0;background: white">免责声明</div>
             <div style="padding:40px 8px 70px;overflow: auto">


             <div id="message"></div>

             </div>


        <div style="position: fixed;bottom:0;height: auto;width: 100%">
            <div  style="text-align: left;background: white;" onclick="clickCheckbox()">
                <input type="checkbox" id="check1"/>
                <span  class="checkSpan">I have read and agree to this disclaimer</span>
            </div>
            <div style="justify-content: center;align-items: center;background: white;width: 100%;display: flex;border-top: 1px solid #eee;">
                <input type="button" style='flex: 1;height: 50px;line-height:50px' onclick="cancel()" value="取消" />
                <input type="button" style="flex: 1;height: 50px;line-height:50px"  onclick="sure()" value="确定"/>
            </div>
        </div>
     </div>

 </div>
</body>
<script>
    var msg='<div><p style="font-size:12pt; line-height:115%; margin:0pt"><span style="font-family:宋体; font-size:12pt">为了尽可以及用户是否按照正常流程操作。</span></p><p style="font-size:12pt; line-height:115%; margin:0pt"><span style="font-family:宋体; font-size:12pt">我司对本条款持最终解释权。</span></p><p style="font-size:10.5pt; line-height:115%; margin:0pt 0pt 10pt; orphans:0; text-align:justify; widows:0"><span style="font-family:Calibri; font-size:10.5pt">&#xa0;</span></p></div><div class="cnzz" style="display: none;">\n'

    window.onload=function () {
        document.getElementById('message').insertAdjacentHTML("afterEnd",msg)
    }
    function set_app(params) {
        console.log(params)
        if (/android/i.test(navigator.userAgent)) {
            try {
                window.android.set_app(params)
            } catch (e) {
                console.log(e)
            }
        } else if (/ios|iphone|ipod|pad/i.test(navigator.userAgent)) {
            try {
                window.webkit.messageHandlers.set_app.postMessage(params)
            } catch (e) {
                console.log(e)
            }
        }
    }
    function cancel(){
        document.getElementById('check1').checked=false
        this.set_app('0')
    }

    function clickCheckbox(){
        document.getElementById('check1').checked=true
        document.getElementsByClassName('checkSpan')[0].style.color = "black"
    }
     function sure(){
        var state=document.getElementById('check1').checked
               if(state){
                   this.set_app('1')
               }else {
                   document.getElementsByClassName('checkSpan')[0].style.color = "red"
               }
            }

</script>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值