我能夠從websocket解壓二進制數據到一個字符串,併成功地能夠顯示文本字符串(使用console.log),但無法使用正確的方式將輸出分配給文檔ID ...二進制數據到字符串轉換失敗
var a = String.fromCharCode.apply(null, new Uint8Array(msg.data));
console.log("output: " + a);
// fails here :(
document.getElementById("session0").textContext = a + "\n";
// if the msg data is a text field this is fine
document.getElementById("session0").textContext = msg.data + "\n";
知道的任何幫助..
感謝
您的意思是在那裏鍵入textContent而不是textContext? –
謝謝,真是一個....!謝謝......有沒有辦法將緩衝區的一部分分配給一個元素? – slickfive
恐怕我不知道。我建議你用一個jsfiddle或jsbin例子來編寫一個新的問題。 –