1
我有一個輸入字段,它有助於一個人進行對話但在convo中扮演這兩個角色。我希望儘可能地接近我想要進行文本對話的內容,但我似乎無法理解如何在文本出現時對文本進行設置。如何從輸入字段通過javascript函數設置文本樣式
截至目前,用戶鍵入文本並點擊兩個按鈕中的一個,每個按鈕都加載了以下功能來拉動文本,創建div,文本節點,將它們追加並放置在頁面中。
我試着對初始輸入進行樣式設計,但是這只是簡化了輸入字段的樣式,並不影響實際的輸出。
我試着在每一步的方法中添加樣式,將其保存到p,div,文本節點的變量中,然後放入文檔中...每次函數失敗。
我試過屬性方法和innerhtml方法。
什麼工作?至少我會喜歡這個功能來粗體對齊文本。接下來最好的方法是在它後面添加一個ng-app的內容,這樣它就會告訴我:(文本在這裏),然後是我的未來自我:(這裏是文本)......我感覺只會涉及一個設置爲變量的字符串。但設置x = {{name}}導致該功能失敗。我知道theres使用firebug來了解這些失敗的一種方法,但我還不完全理解。有什麼建議麼?
<script>
function changeTextComment4(destination){
// to be modified from the above to change the location of the dump
// this function ADDS a comment from the comment field to the div w id comment near it...
var userInput = document.getElementById('userInputS1').value;
// get the input from the user
// 3 make the div a panel
var para = document.createElement("P");
// assignment of attributes
var t = document.createTextNode(userInput);
para.appendChild(t);
// add comment area
// place the item
var destination = document.getElementById(destination)
destination.insertBefore(para, destination.firstChild);
document.getElementById('userInputS1').value = "";
document.getElementById('userInputS1').focus();}
</script>
這個工作增添風采!我可以通過DOM方法添加標籤,然後單獨設置標籤的樣式,它就可以工作。謝謝。 –