为什么“<br>"显示而不是引起中断
Why is "<br>" displaying instead of causing a break
有人问我这个问题,我很抱歉,但我没有看到问题的答案。我试图将结果显示在文本框中,当我使用"<br>
"时,它实际上是在写br,而不是创建换行
我正在向文本框显示
这是它的html
<input type ="text" name="display" id="display" class="display" readonly>
这是我使用的javascript
document.getElementById("display").value = "The highest test score is: " + max + "<br>"+
"The lowest test score is: " + min + "<br>" +
"The average test score is: " + avg + "<br>" +
"The scores are: " + results;
我以前使用过这个,但我已经向<p>
显示了它,它起了作用。是输入类型的东西吗??
文本框的值不会被解释为HTML。
这里的解决方案是使用'n
:
document.getElementById("display").value = "The highest test score is: " + max + "'n"+
"The lowest test score is: " + min + "'n" +
"The average test score is: " + avg + "'n" +
"The scores are: " + results;
但是您可能应该在这里使用textarea
而不是input
,因为您想要显示几行。
<input type="text" />
只能包含单行文本,您应该使用textarea
元素,它可以包含多行,如下所示:
<textarea>
this
is
some text
</textarea>
请注意,设置textarea.value
也会起作用。
使用textarea而不是input type="text"根据自己的喜好添加"cols"answers"rows"属性,然后将br标记替换为"''n"。
<textarea id="display" cols="15" rows="5" ></textarea>
document.getElementById("display").value = "The highest test score is: " + max + "'n"+
"The lowest test score is: " + min + "'n" +
"The average test score is: " + avg + "'n" +
"The scores are: " + results;
相关文章:
- 铬:“;未捕获的语法错误:意外的标记:"
- 可以设置“;文件名"发生错误时显示的内联脚本标记的
- JS表单提交"无法使用Chrome数据保护程序加载此页面.尝试重新加载页面.调试信息:POST CISmtuK
- 检测电话窃听,即:<a href="电话:xxx">在UIWebview上
- 高亮显示与数组字符串一起使用时文本插件中断
- 使用“+="操作人员
- //而不是在src=“”上使用http://"属性
- "未捕获的语法错误:意外的标记}"
- 可以<脚本类型=“;text/javascript”>window.location=“/"</
- "实例范围”;TypeScript类的getter/setter
- Javascript复选框函数:;缺少:在属性id之后"
- "“;变量未引用正确的对象
- "日期“;AJAX请求返回的类型值未定义
- AngularJS ui路由器html5模式中断路由
- 得到"TypeError:无法读取属性'filename'未定义的“;调用“npm start
- Soundcloud api"未捕获的类型错误:无法读取属性'uri'“未定义”;
- "工具提示"jQuery插件坏了
- 递归函数中断
- "锻造;React中的表达式
- 为什么“<br>"显示而不是引起中断