当来自输入字段时,如何通过javascript函数设置文本样式

当来自输入字段时,如何通过javascript函数设置文本样式,javascript,html,angularjs,Javascript,Html,Angularjs,我有一个输入字段,可以帮助一个人进行对话,但在COVA中同时扮演这两个角色。我想尽可能接近文本对话的感觉,但我似乎无法理清文本的风格 此时,用户键入文本并点击两个按钮中的一个,每个按钮都加载以下功能,以提取文本、创建div、text节点、附加它们并将其放置在页面中 我尝试了设置初始输入的样式,但这只是使输入字段设置样式,并不影响实际输出 我尝试在每个步骤中添加样式,将输入保存到变量中,添加到p、div、文本节点中,然后将其放入文档中。。。每次函数失败时 我尝试了属性方法和innerhtml方法

我有一个输入字段,可以帮助一个人进行对话,但在COVA中同时扮演这两个角色。我想尽可能接近文本对话的感觉,但我似乎无法理清文本的风格

此时,用户键入文本并点击两个按钮中的一个,每个按钮都加载以下功能,以提取文本、创建div、text节点、附加它们并将其放置在页面中

我尝试了设置初始输入的样式,但这只是使输入字段设置样式,并不影响实际输出

我尝试在每个步骤中添加样式,将输入保存到变量中,添加到p、div、文本节点中,然后将其放入文档中。。。每次函数失败时

我尝试了属性方法和innerhtml方法

什么有效?至少我会喜欢的功能,以粗体和右对齐的文本。下一个最好的方法是在它后面加上一个ng应用程序的内容,这样它就会显示我:(这里的文本),然后是我未来的自己:(这里的文本)。。。我感觉这只会涉及一个字符串设置为一个变量。。但是设置x={{name}}导致函数失败

我知道有一种方法可以使用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>

函数changeTextComment4(目标){
//从上面修改以更改转储位置
//此函数用于将注释字段中的注释添加到其附近的div w id注释。。。
var userInput=document.getElementById('userInputS1')。值;
//从用户那里获取输入
//3.制作div a面板
var para=document.createElement(“P”);
//属性分配
var t=document.createTextNode(userInput);
第3(t)段;
//添加评论区
//放置项目
var destination=document.getElementById(目的地)
destination.insertBefore(第段,destination.firstChild);
document.getElementById('userInputS1')。value=“”;
document.getElementById('userInputS1').focus();}

您可以通过参考选择器添加样式

#userInputS1{
    color : #F00;
}

这成功了!我可以通过DOM方法添加标记,然后分别设置标记的样式,这样就可以了。非常感谢。