javascript - 命名动态创建的文本区域
问题描述
初学者在这里我的深度!我试图创建文本区域,然后我可以将其发送到数据库。我无法命名文本区域。这是我尝试过的。. .
var node = document.createElement("textarea");
var textnode = document.createTextNode("Comment");
node.appendChild(textnode);
node.setAttribute("id", "commen");
node.setAttribute("name", "comment");
textnode.attr('name', 'com');
textnode.style.width ="100%";
textnode.rows = "400";
textnode.cols ="50";
textnode.id = "myTextArea";
textnode.name = "comments";
textnode.value = "commenters";
node.setAttribute("align", "center");
node.setAttribute("id", "id_you_like");
textnode.setAttribute("id", "id_you_like");
var answerBox = document.getElementById("Answer");
answerBox.style.padding = "0px 0px 0px 0px";
answerBox.setAttribute("align", "center");
answerBox.appendChild(node);
我似乎无法为“Answer”Div 中动态创建的文本区域设置名称。它确实创建了一个 taxtarea,但没有附加名称或 ID。
提前致谢。
解决方案
如果您删除文本节点并尝试在节点上设置样式,则会留下 this,如果您使用开发控制台进行检查,它确实有一个带有名称和 id 的 textarea 附加到它:
var node = document.createElement("textarea");
node.setAttribute("id", "commen");
node.setAttribute("name", "comment");
node.setAttribute("align", "center");
node.setAttribute("id", "id_you_like");
var answerBox = document.getElementById("Answer");
answerBox.setAttribute("align", "center");
answerBox.appendChild(node);
<div id="Answer"/>
推荐阅读
- java - Solr 较短的字段得分较高
- javascript - 如何为表格的行添加分页
- android - Android Uri 构建忽略参数,除非至少存在一个参数
- reactjs - 无法从 immutable.js 导入 RecordFactory
- javascript - 当前日期的红框未显示
- elasticsearch - Logstash 失败,没有 SSL/TLS 记录
- android - Android中的响应式字体大小
- html - 如何将按钮与文本放在同一行?HTML
- java - KafkaTemplate 和 KafkaProducer 发送方法的区别?
- json - 如何解析包含嵌套 json 形式数据的 kafka 主题?