[英]How to set attributes in monaco editor textarea?
My question is about monaco editor and how to set the name
attribute? 我的问题是关于摩纳哥编辑器以及如何设置
name
属性? I've wrapped the editor in a <form>
and I know there it is hidden <textarea>
- I want to set some attributes. 我把编辑器包装在
<form>
,我知道它隐藏了<textarea>
- 我想设置一些属性。
What is the best way to set attributes? 设置属性的最佳方法是什么?
Is there a configuration ? 有配置吗?
The only way I found is to use this code, but it's a little hacking: $(editor.getDomNode()).find('textarea').attr('name', 'content');
我发现的唯一方法是使用这个代码,但它有点黑客攻击:
$(editor.getDomNode()).find('textarea').attr('name', 'content');
Full code example: 完整代码示例:
var editor;
require.config({ paths: { 'vs': '/lib/monaco-editor/dist/min/vs' } });
require(['vs/editor/editor.main'], function () {
var editorOptions = {
value: '<div> Hello World! </div>',
language: 'html',
};
editor = monaco.editor.create(document.getElementById('container'), editorOptions);
// The only way to set name
$(editor.getDomNode()).find('textarea').attr('name', 'content');
});
Actually monaco editor
puts only a part of the visible content in the <textarea>
. 实际上,
monaco editor
只在<textarea>
放置了可见内容的一部分。 In that case, it will submit only part of the content. 在这种情况下,它只会提交部分内容。 The best solution is to use another hidden
<textarea>
and set the actual content using editor.getValue()
function kjust before submit the form. 最好的解决方案是使用另一个隐藏的
<textarea>
并在提交表单之前使用editor.getValue()
函数kjust设置实际内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.