Firebaseデータベースからすべての質問と回答を表示しようとしています。それはうまく表示されていますが、質問と回答の間にスペースがないので、醜いように見えます。私はcreateElement
機能と.innerHTML
を使用して改行しないスペースを追加しようとしました。何も働いていません。これまで私が持っているコードは次のとおりです:あなたの助けをありがとう!javacriptで要素間に空白/改行を追加する
<button id="all" onclick="button()"> View All </button>
<h4> All Users: </h4>
<script>
function button(){
var userRef = new Firebase("https://speedpoll-1fd08.firebaseio.com");
userRef.on("value", function(snapshot) {
// The callback function will get called twice, once for "fred" and once for "barney"
snapshot.forEach(function(childSnapshot) {
// key will be "fred" the first time and "barney" the second time
var key = console.log(childSnapshot.key());
// childData will be the actual contents of the child
// var userInfo = console.log(childSnapshot.val());
var element = document.getElementById("viewAll");
var para = document.createElement("h5");
var node = document.createTextNode("Question: " + childSnapshot.key());
console.log(childSnapshot.child("Option1").child('Response1').val());
var node1= document.createTextNode("Response 1: " + childSnapshot.child("Option1").child('Response1').val());
//var space = document.createElement(" ");
element.innerHTML += " ";
var node2= document.createTextNode("Response 2: " + childSnapshot.child('Option2').child('Response2').val());
var node3= document.createTextNode("Response 3: " + childSnapshot.child('Option3').child('Response3').val());
para.appendChild(node);
//para.appendChild(space);
para.appendChild(node1);
para.appendChild(node2);
para.appendChild(node3);
element.appendChild(para);
});
});
}
</script>
<div id="viewAll">
</div>
ここで説明したようにあなたは、
<hr>
要素を追加することによって、行を追加することができます
P.S.を何らかの理由で貼り付けられたコードにはボタンがありません。 –
単純な
タグを使用してスペースを作成してみませんか? – Eric
どのように私はjavascriptの中でそれを実装するのですか? –