我正在创建一个简单的后端应用程序,用户可以通过该应用程序创建/更新/删除数据库行(在本例中为作业列表).
当用户编辑现有列表时,我正在尝试使用该现有行中的数据预填充大部分HTML表单.我已成功使用"value"属性对文本输入执行此操作,并在每个选项标记中使用一些php选择:if([conditionforoption]){echo'selected'}.
我在预填充时遇到问题的输入类型是textarea ...当用户加载页面时,有关如何获取textarea输入中存在的现有数据(长varchar字符串)的任何想法?
我试图远离javascript解决方案,如果可能的话,但我会在必要时使用它.
AGo*_*ame 121
<textarea>This is where you put the text.</textarea>
Run Code Online (Sandbox Code Playgroud)
Tim*_*Tim 27
如果你的问题是,如何填写textarea:
<textarea>
Here is the data you want to show in your textarea
</textarea>
Run Code Online (Sandbox Code Playgroud)
小智 11
这是一个HTML5标签,只适用于现代浏览器:)
<textarea placeholder="Add a comment..."></textarea>
Run Code Online (Sandbox Code Playgroud)
要填写 textarea 的值,请在标签内插入文本,如下所示:
<textarea>Example of content</textarea>
Run Code Online (Sandbox Code Playgroud)
在代码中,“内容示例”文本将成为 textarea 的值。如果要添加到值,即取一个值并添加另一个字符串或数据类型来执行此操作,您可以在 JavaScript 中执行此操作:
<textarea id="test">Example of</textarea>
<!--I want to say "content" in the textarea's value, so ultimately it will say
Example of content. Pressing the "Add String To Value" button again will add another "content" string onto the value.-->
<input type="button" value="Add String To Value" onclick="add()"/>
<!--The above will call the function that'll add a string to the textarea's value-->
<script>
function add() {
//We first get the current value of the textarea
var x = document.getElementById("test").value;
//Then we concatenate the string "content" onto it
document.getElementById("test").value = x+" content";
}
</script>
Run Code Online (Sandbox Code Playgroud)
希望给你一个答案和一个想法!