繁体   English   中英

如何使用 JS、HTML 添加带有函数的换行符

[英]How to add a line break with function using JS, HTML

它将在 FirefoxOS 的应用程序中使用。 正在使用 WebIDE Firefoxos 2.2 进行测试

<p>
    <input type="text" align="right" id="screen" name="kijelzo"/>               
    <button onclick="add()" name="add" >Add</button>
    <button onclick="clear()" name="add" >Clear</button>
</p>
<h1 id="stuff">
</h1>
<script>
    function add(){                                                        
        var plusz=document.getElementById('screen').value;
        var element=document.getElementById('stuff');
        element.innerHTML=element.innerHTML+plusz;
        // i'd like to have a linebreak after every single added element.
    }
</script>

您可以使用<br>标签在 HTML 中添加换行符。

element.innerHTML = element.innerHTML + "<br />" + plusz;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM