简体   繁体   English

如何在php变量中将样式代码执行为html textarea

[英]how to execute style code in a php variable to html textarea

I have a php variable: 我有一个php变量:

$correction = <span style="background:yellow">iiii</span> am a good person.

This variable is sent to ajax from php under the 该变量从php下的php发送到ajax。

success: function(msg)
{       
    $("#target").val(msg); // msg is the $correction string
}

then it gets displayed into a textarea. 然后将其显示在文本区域中。 However, i want the style to execute instead of displaying the html code in the $correction. 但是,我希望样式执行,而不是在$ correction中显示html代码。

It detects misspelling and highlights it in yellow but i have no ideas how to make it display the string. 它会检测拼写错误并以黄色突出显示它,但我不知道如何使它显示字符串。

I have tried creating a function in the ajax success function and send the msg variable to a Javascript function but it did not work. 我尝试过在ajax成功函数中创建一个函数,并将msg变量发送到Javascript函数,但是它不起作用。

I have tried adding <body></body> tag on it and even replaced the 我尝试在其上添加<body></body>标记,甚至替换了

<span> to <div id="display" style="background:yellow">iiii</div> am a good person.

and it still did not work. 而且仍然没有用。

expected result: <mark>iiii</mark> am a good person. 预期的结果: <mark>iiii</mark> am a good person.

actual result: <span style="background:yellow">iiii</span> am a good person. 实际结果: <span style="background:yellow">iiii</span> am a good person.

Thanks for helping. 感谢您的帮助。

You can not set an HTML - Code inside an <textarea/> https://www.w3schools.com/tags/tag_textarea.asp because it is an "multi-line text input" object. 您不能在<textarea/> https://www.w3schools.com/tags/tag_textarea.asp中设置<textarea/>代码,因为它是“多行文本输入”对象。

If you want it inside an textarea, you can do it with an <div contenteditable="true">your editable content</div> workaround on an DIV-tag. 如果您希望在文本区域内使用它,则可以使用DIV标签上的<div contenteditable="true">your editable content</div>解决方法。 https://www.w3schools.com/tags/att_global_contenteditable.asp https://www.w3schools.com/tags/att_global_contenteditable.asp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM