欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

js获取代码片下载并生成HTML

程序员文章站 2022-06-19 16:13:13
好好学习 ,天天向上。Are you ready?例子:js获取代码片下载并生成HTML js获取代码片下载并生成HTML</...</div> <div class="content"> <h2> <a id="_Are_you_readyhttpsimgblogcsdnimgcn20181207195806897gif_0" target="_blank" rel="nofollow" href="/default/index/url?u=aHR0cHM6Ly93d3cuMTBxaWFud2FuLmNvbQ=="></a>好好学习 ,天天向上。Are you ready?<img onerror="this.src='/statics/superweb999/images/image_error.jpg'"src="/default/index/img?u=aHR0cDovL2ltYWdlczUuMTBxaWFud2FuLmNvbS8xMHFpYW53YW4vMjAyMDEyMTIvYl8wXzIwMjAxMjEyMTY1OTMzODYzNy5naWY=" alt="js获取代码片下载并生成HTML" title="js获取代码片下载并生成HTML"> </h2> <p>例子:js获取代码片下载并生成HTML</p> <pre><code class="prism language-javascript"><span class="token operator"><</span><span class="token operator">!</span><span class="token constant">DOCTYPE</span> html<span class="token operator">></span> <span class="token operator"><</span>html lang<span class="token operator">=</span><span class="token string">"en"</span><span class="token operator">></span> <span class="token operator"><</span>head<span class="token operator">></span> <span class="token operator"><</span>meta charset<span class="token operator">=</span><span class="token string">"UTF-8"</span><span class="token operator">></span> <span class="token operator"><</span>meta name<span class="token operator">=</span><span class="token string">"viewport"</span> content<span class="token operator">=</span><span class="token string">"width=device-width, initial-scale=1.0"</span><span class="token operator">></span> <span class="token operator"><</span>title<span class="token operator">></span>js获取代码片下载并生成<span class="token constant">HTML</span><span class="token operator"><</span><span class="token operator">/</span>title<span class="token operator">></span> <span class="token operator"><</span><span class="token operator">/</span>head<span class="token operator">></span> <span class="token operator"><</span>body<span class="token operator">></span> <span class="token operator"><</span>button id<span class="token operator">=</span><span class="token string">"btn"</span><span class="token operator">></span>下载<span class="token constant">HTML</span><span class="token operator"><</span><span class="token operator">/</span>button<span class="token operator">></span> <span class="token operator"><</span><span class="token operator">/</span>body<span class="token operator">></span> <span class="token operator"><</span>script<span class="token operator">></span> <span class="token keyword">let</span> text <span class="token operator">=</span> <span class="token string">'<p>下载HTML成功</p>'</span> <span class="token keyword">let</span> btn <span class="token operator">=</span> document<span class="token punctuation">.</span><span class="token function">getElementById</span><span class="token punctuation">(</span><span class="token string">'btn'</span><span class="token punctuation">)</span> btn<span class="token punctuation">.</span><span class="token function">addEventListener</span><span class="token punctuation">(</span><span class="token string">'click'</span><span class="token punctuation">,</span> handleClick<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">function</span> <span class="token function">handleClick</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token function">funDownload</span><span class="token punctuation">(</span>text<span class="token punctuation">,</span> <span class="token string">'download.html'</span><span class="token punctuation">)</span> window<span class="token punctuation">.</span><span class="token function">open</span><span class="token punctuation">(</span><span class="token string">'download.html'</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> <span class="token keyword">function</span> <span class="token function">funDownload</span><span class="token punctuation">(</span>content<span class="token punctuation">,</span> filename<span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">var</span> eleLink <span class="token operator">=</span> document<span class="token punctuation">.</span><span class="token function">createElement</span><span class="token punctuation">(</span><span class="token string">"a"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> eleLink<span class="token punctuation">.</span>download <span class="token operator">=</span> filename<span class="token punctuation">;</span> eleLink<span class="token punctuation">.</span>style<span class="token punctuation">.</span>display <span class="token operator">=</span> <span class="token string">"none"</span><span class="token punctuation">;</span> <span class="token keyword">var</span> blob <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Blob</span><span class="token punctuation">(</span><span class="token punctuation">[</span>content<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span> eleLink<span class="token punctuation">.</span>href <span class="token operator">=</span> <span class="token constant">URL</span><span class="token punctuation">.</span><span class="token function">createObjectURL</span><span class="token punctuation">(</span>blob<span class="token punctuation">)</span><span class="token punctuation">;</span> document<span class="token punctuation">.</span>body<span class="token punctuation">.</span><span class="token function">appendChild</span><span class="token punctuation">(</span>eleLink<span class="token punctuation">)</span><span class="token punctuation">;</span> eleLink<span class="token punctuation">.</span><span class="token function">click</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> document<span class="token punctuation">.</span>body<span class="token punctuation">.</span><span class="token function">removeChild</span><span class="token punctuation">(</span>eleLink<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token operator"><</span><span class="token operator">/</span>script<span class="token operator">></span> <span class="token operator"><</span><span class="token operator">/</span>html<span class="token operator">></span> </code></pre> <p>本文地址:https://blog.csdn.net/weixin_43654258/article/details/111028802</p> </div> <div class="tags"> 相关标签: <a href="/t/js%E7%94%9F%E6%88%90HTML/" target="_blank"> js生成HTML </a> <a href="/t/javascript/" target="_blank"> javascript </a> <a href="/t/html5/" target="_blank"> html5 </a> </div> <div class="info-pre-next"> <p> 上一篇: <a href="/article/1455232.html"> 将该演示文稿与原始版本合并在一起然后审阅这些更改 </a> </p> <p> 下一篇: <a href="/article/1455234.html"> 必须知道的排版六艺可以帮你做出拥有漂亮版面的PPT </a> </p> </div> <div class="wz_tuijian"> <p> 推荐阅读 </p> <ul> <li> <a href="/article/1455233.html" target="_blank" title="js获取代码片下载并生成HTML"> <h2> js获取代码片下载并生成HTML </h2> </a> </li> <li> <a href="/article/991557.html" target="_blank" title="jquery $("nam") 获取不到js生成的html的id ? 来看下代码"> <h2> jquery $("nam") 获取不到js生成的html的id ? 来看下代码 </h2> </a> </li> <li> <a href="/article/927573.html" target="_blank" title="jquery $("nam") 获取不到js生成的html的id ? 来看下代码"> <h2> jquery $("nam") 获取不到js生成的html的id ? 来看下代码 </h2> </a> </li> <li> <a href="/article/804530.html" target="_blank" title="jquery $("nam") 获取不到js生成的html的id ? 来看下代码"> <h2> jquery $("nam") 获取不到js生成的html的id ? 来看下代码 </h2> </a> </li> <li> <a href="/article/99524.html" target="_blank" title="js获取代码片下载并生成HTML"> <h2> js获取代码片下载并生成HTML </h2> </a> </li> </ul> </div> </article> </div> </main> <footer><div class="box"><div class="ft_nav"><div class="ft_about"><p>关于网站</p><ul><li><a href="/sitemap.xml" target="_blank" title="网站地图">网站地图</a></li><li><a href="/list/2/" title="最新程序员文章站">最新程序员文章站</a></li></ul></div><div class="ft_contact"><ul><li>本站所有数据收集于网络如有侵犯到您的权益,请联系我们进行下架处理。</li><li class="email_show"></li></ul></div></div><div class="copyright"><div class="cr_left"><p> 备案号:<a href="https://beian.miit.gov.cn/#/Integrated/index" target="_blank">粤ICP备20058927号</a></p><p>© Copyright © 2020-2022 www.superweb999.com 程序员文章站. </p></div></div></div></footer> </body> </html>