Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.8k views
in Technique[技术] by (71.8m points)

js变量里保存html标签片段报错

起因:我用了百度Ueditor插件在vue里,目的是生成H5页面,所以我只Ueditor获取了html片段,为的是自己添加html的头部和尾部;

1.vue data操作

header:'<!DOCTYPE html><html lang="zh-CN"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"><style type="text/css">html,body {height: 100%;width: calc(100% - 10px);padding: 0;margin: 0;}</style><style type="text/css">img{height: auto !important;width:100% !important;};</style><style type="text/css">#content {width: 90%;height: 100%;padding: 0;margin: 10px auto;};</style></head><body>',
footer:'</body></html>'

//Ueditor获取的片段例子
content='<section><>123</section>'
//合并成完整的html
html = header + content + footer;

我把这三部分拼接成了完整的html存到了后台;

2.vue变量写法没报错,生成H5页报错

vue变量写法没报错,换成html页面写法就错了

let header='<!DOCTYPE html><html lang="zh-CN"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"><style type="text/css">html,body {height: 100%;width: calc(100% - 10px);padding: 0;margin: 0;}</style><style type="text/css">img{height: auto !important;width:100% !important;};</style><style type="text/css">#content {width: 90%;height: 100%;padding: 0;margin: 10px auto;};</style></head><body>';
let footer='</body></html>' //报错了此处

在html页面let footer='</body></html>' 片段报错了此处~~~~
image
请各位帮看看怎么写才不会报错呢,感谢~~~
附上报错码

<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
</head>
<body>
    <div id="content">12343</div>
    <script type="text/javascript">
        let footer='</body></html>'              
    </script>
</body>

</html>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

你这个代码片段不连贯,也没看到vue相关联的代码
从你上面的代码来看 是从html里面嵌套了一个 html???


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...