如何使用 Javascript 或使用 JQuery 的帮助从所见即所得中获取价值?
我想问。我想创建一个博客,但使用了Microsoft Word风格的文本编辑器。如果假设使用香草JavaScript或纯JavaScript或使用jQuery的帮助?
我的代码:
<script src="https://code.jquery.com/jquery-3.6.0.js" integrity="sha256-H+K7U5CnXl1h5ywQfKtSj8PCmoN9aaq30gDh27Xc0jk=" crossorigin="anonymous"></script>
<!-- CDN WYSIWYG (TINYMICE) -->
<script src="https://cdn.tiny.cloud/1/fjxlmvgx0f36t65lwkpdwdyrxxahi85ni9wp3e2xp17gjitr/tinymce/6/tinymce.min.js" referrerpolicy="origin"></script>
</head>
<body>
<!-- Text-Area -->
<textarea id="my_text"></textarea>
<!-- Button Get Value -->
<button id="value_button">Get Value</button>
<script>
// Install WYSIWYS (TINYMICE)
tinymce.init({
selector: 'textarea',
plugins: 'a11ychecker advcode casechange export formatpainter image editimage linkchecker autolink lists checklist media mediaembed pageembed permanentpen powerpaste table advtable tableofcontents tinycomments tinymcespellchecker',
toolbar: 'a11ycheck addcomment showcomments casechange checklist code export formatpainter image editimage pageembed permanentpen table tableofcontents',
toolbar_mode: 'floating',
tinycomments_mode: 'embedded',
tinycomments_author: 'Author name',
});
// Dom (get id:my_text & value_button)
let my_text = document.getElementById("my_text");
let value_button = document.getElementById("value_button");
// get value in console
value_button.addEventListener("click",()=>{
console.log(my_text.value)
})
</script>
我想先获取值。就像想写“星期四”一样
,出现的是
“ &lt; p&gt;星期四&lt;/p&gt;
“
我的障碍,我输入了任何值是“”(空)
注:我的wysiwyg是tinymice
,但是,但是如果您有另一种类型的Wysiwyg,我将尝试 谢谢
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
TinyMCE 有一个 API 来获取其当前内容:
getContent()
- https://www.tiny.cloud/docs/api/tinymce/tinymce.editor/#getcontent对于一些背景,当您加载 TinyMCE 时,它会覆盖您的
textarea
带有iframe
,因此当您在 TinyMCE 中输入内容时,您不会更新textarea
。话虽这么说,有一个 API 调用可以使 TinyMCE 将其当前内容推回到
textarea
中:triggerSave()
- https://www.tiny.cloud/docs/api/tinymce/root_tinymce/#triggersave...因此,如果您需要专门使用
textarea
执行某些操作,您可以首先调用triggerSave()
。TinyMCE has an API to get its current content:
getContent()
- https://www.tiny.cloud/docs/api/tinymce/tinymce.editor/#getcontentFor some background, when you load TinyMCE it overlays your
textarea
with aniframe
so when you are typing into TinyMCE you are not updating thetextarea
.That being said, there is an API call to make TinyMCE push its current content back into the
textarea
:triggerSave()
- https://www.tiny.cloud/docs/api/tinymce/root_tinymce/#triggersave...so if you need to do something specifically with the
textarea
you can calltriggerSave()
first.