如何将一段html代码分配给一个javascript变量 [英] how to assign a block of html code to a javascript variable

查看:94
本文介绍了如何将一段html代码分配给一个javascript变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < div class ='保存了一段HTML代码到javascript变量的语法是什么? '> 
< div> test.test< / div> < div class ='remove'> [移除]< / div>< / div>

我想将上面的代码赋给变量'test'

  var test =< div class ='saved'> 
< div> test.test< / div>< div class = '删除' > [删除] LT; / DIV>< / DIV>中;

但它不起作用,这是分配代码的正确语法吗?



TIA

解决方案

  var test =< ; div class ='saved'>+ 
< div> test.test< / div>< div class ='remove'> [Remove]< / div>< / div> ;;

如果您需要换行符,可以添加\\\


what is the syntax to store a block of html code to a javascript variable?

<div class='saved' >
<div >test.test</div> <div class='remove'>[Remove]</div></div>

I want to assign the above code to a variable 'test'

var test = "<div class='saved' >
<div >test.test</div> <div class='remove'>[Remove]</div></div>";

but it does not work, which are the correct syntax for assigning the code?

TIA

解决方案

 var test = "<div class='saved' >"+
 "<div >test.test</div> <div class='remove'>[Remove]</div></div>";

You can add "\n" if you require line-break.

这篇关于如何将一段html代码分配给一个javascript变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆