我试图在每次运行函数时输出以下内容:
<object id="video" width="500" height="500" type="application/x-shockwave-flash" data="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf">
<param name="movie" value="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" />
<param name="allowfullscreen" value="true" />
<param name="flashvars" value='config={"playlist":["poster_location", {"url": "clip_location","autoPlay":false,"autoBuffering":true}]}' />
<img src="poster_location" width="500" height="500" alt="Poster Image" title="No video playback capabilities." />
</object>
我想在代码的某些部分插入 javascript 变量(以更改视频/海报等)。
我意识到这可以通过使用 document.getElementById
定位需要更改的每个部分并以这种方式进行更改来完成,但是由于各种原因,我需要删除并重新构建每次运行函数时的整个元素。
那么有没有一种类似php的echo的方式使用javascript输出html的好方法呢?
如果有帮助的话,我也在使用 jQuery。
最佳答案
您可以像这样在 JavaScript 中使用多行字符串:
var str = "Blah blah blah \
note the backslash that escapes the end of line";
或者,您可以简单地关闭字符串并在下一行重新打开它:
var str = "Blah blah blah "
+"and this way you don't get 'Empty Text Node' all over your DOM";
关于javascript - 如何使用 Javascript 输出带有变量插值的多行 HTML?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4328132/