2016-04-25 11 views
0

こんにちは私はこれは非常に単純な質問かもしれないと思うが、私はどこでも答えを見つけることができません。全体のページの代わりに表の1つのセルにJavascript

私は私のデータベースから情報を引き出し、私はそれがアップテーブルの一つのセルにあることを取得しようとしていますが、それは全体のページへ

what the system is outputting

出力されるJavaScript関数を持っていますHTML

<tr> 
<td class="tg-baqh" id='Emp1'></td> 
<td class="tg-yw4l"><input type="text" placeholder="enter shift" class="form-control" id='shiftInput'></td> 
<td class="tg-yw4l"><input type="text" placeholder="enter shift" class="form-control" id='shiftInput'></td> 
<td class="tg-yw4l"><input type="text" placeholder="enter shift" class="form-control"></td> 
<td class="tg-yw4l"><input type="text" placeholder="enter shift" class="form-control"></td> 
<td class="tg-yw4l"><input type="text" placeholder="enter shift" class="form-control"></td> 
<td class="tg-yw4l"><input type="text" placeholder="enter shift" class="form-control"></td> 
<td class="tg-yw4l"><input type="text" placeholder="enter shift" class="form-control"></td> 
<td class="tg-yw4l">30/16</td> 

Javascriptを

 $(function Emp1(){ 

    // Get a database reference to our posts 
    var employeeref = new Firebase("https://shiftsapp.firebaseio.com/employees/emp1"); 

    // Attach an asynchronous callback to read the data at our posts reference 
    employeeref.on("value", function(snapshot) { 
    console.log(snapshot.val()); 
    document.write(snapshot.val()); 
    }, function (errorObject) { 
     console.log("The read failed: " + errorObject.code); 
     }); 

     }); 
+1

これはドキュメントの上書きですか? – adeneo

+0

ここから画像を削除し、質問の一部としてコード自体を投稿する必要があります。 – ManoDestra

+1

@ManoDestraコードを追加して画像を取り除きました。 – kelliehughesspare

答えて

1

にdocument.write()メソッドではなく、あなたがdocument.getElementByIdまたはdocument.getElementByClassNameまたはいくつかの要素セレクター方法、そしてreplaceまたはappendだけその要素のHTMLを使用する必要があり、文書全体の要素を置き換えます。もしあなたがJQueryを使っているなら、次のようなことができます:

var resutlHtml = "<div>test</div>"; //this is your html response 
$('#tableId .tablecellclass').html(resultHtml); 
関連する問題