[英]How to style text via a javascript function when coming from an input field
I have one input field that facilitates a person having a conversation but playing both roles in the convo. 我有一个输入字段,可帮助一个人进行对话,但在convo中扮演两个角色。 I want to get as close as I can to what its like to have a text conversation, but I cannot seem to sort out how to style the text when it comes through. 我想尽可能地接近进行文本对话的感觉,但是我似乎无法弄清楚文本通过时如何设置样式。
As of the moment, the user types the text and hits one of two buttons, each is loaded with the following function to pull the text, create a div, text node, append them and place in the page. 到目前为止,用户键入文本并单击两个按钮之一,每个按钮都加载了以下功能以拉出文本,创建div,文本节点,将其附加并放置在页面中。
I tried styling the initial input but that simply makes the input field styled, does not affect the actual output. 我尝试设置初始输入的样式,但这仅使输入字段具有样式,不会影响实际输出。
I tried adding style at each step of the way, to the variable I saved the input in, to the p, the div, the text node, and after placing it in the doc... each time the function failed. 我尝试在方法的每个步骤中将样式添加到将输入保存到的变量,p,div,文本节点中,然后将其放置到文档中……每当函数失败时,就添加样式。
I tried the attribute method and an innerhtml approach. 我尝试了属性方法和innerhtml方法。
What would work? 什么会起作用? At minimum I would love the function to bold and right align the text. 至少我希望该功能使文本加粗和右对齐。 Next best would be to append it with the contents of an ng-app so it says Me: (text here), then My future self: (text here)... which I sense would just involve a string set to a variable.. but setting x = {{name}} caused the function to fail.. 第二个最好的办法是将它附加到ng-app的内容中,这样它说我:(此处为文本),然后为我的未来自我:(此处为文本)...我感觉这将只涉及设置为变量的字符串。 。,但是设置x = {{name}}会导致函数失败。
I know theres a way to use firebug to understand these failures, but I am not quite understanding that yet. 我知道有一种方法可以使用Firebug来了解这些故障,但是我还不太了解。 Any suggestions? 有什么建议么?
<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>
you can add style by referring to the selector 您可以通过引用选择器来添加样式
#userInputS1{
color : #F00;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.