您好,欢迎来到划拓汽车网。
搜索
您的当前位置:首页如何用JS实现直接运行html的代码

如何用JS实现直接运行html的代码

来源:划拓汽车网
 这篇文章主要介绍了JS实现直接运行html代码的方法,涉及javascript窗口操作相关实现技巧,需要的朋友可以参考下

本文实例讲述了JS实现直接运行html代码的方法。分享给大家供大家参考,具体如下:

1、实例代码:

<!DOCTYPE html>
<html>
 <head>
 <meta charset='utf-8'/>
 <title>直接运行 html 代码</title>
 </head>
 <body>
 <textarea style='width:300px;height:200px;' id='txtCode'></textarea><br/>
 <input type='button' value='直接运行' id='btnRun'/>
 <script>
 document.getElementById('btnRun').onclick = function(){
 var runHtml = document.getElementById('txtCode').value;
 if(runHtml){
 var win = window.open('', '运行窗口');
 win.document.open();
 win.document.write(runHtml);
 win.document.close();
 }
 else{
 alert('请输入!');
 }
 }
 </script>
 </body>
</html>

2、运行效果图如下:

Copyright © 2019- huatuoask.net 版权所有

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务