文本框的Javascript值转换为其他html标签(td)onclick [英] Javascript value of textbox into other html tag (td) onclick

查看:93
本文介绍了文本框的Javascript值转换为其他html标签(td)onclick的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在文本框中有一些值,下面有按钮.Onclick 我需要用这个值更新内部(这将是 HTML 标签)我试过了:

I have some value in textbox and lower have the button. Onclick I need to update the inside of with this value (which will be HTML tags) I have tried:

javascript:

javascript:

<script>
function copyfunction() {
    var textarea = document.getElementById('mytextarea');
    var preview = document.getElementById('html_preview');
    preview.innerHTML = textarea.value;
}
</script>

html:

<textarea id=mytextarea name=text>some initial text</textarea>
<button type=button onclick=\"copyfunction();\">Preview</button>

<table><tr>
    <td id=html_preview></td>
</tr></table>

但它没有做任何事情

抱歉离开转义\但我在php中这样做,所以:

sorry for leaving escapes \ but im doing this in php, so:

echo "<button type=button onclick=\"copyfunction();\">Preview</button>";

-它不起作用,但是当我用简单的 html 执行它时,它确实起作用了 :(

- and it doesnt work, however when i do it in simple html, then it does :(

我很抱歉你的所有努力,它工作正常,但是我正在实施 TinyMCE 并且它不适用于此应用程序 :(

im sorry for all of your efforts, it work fine, however im implementing TinyMCE and it doesnt work with this app :(

推荐答案

一旦 TinyMCE 初始化并在页面上可见,原来的 textarea 不再可见.当您初始化 TinyMCE 时,它会呈现一个 iframe 作为内容编辑区域(有效地隐藏了 textarea).

Once TinyMCE is initialized and visible on the page the original textarea is no longer visible. When you init TinyMCE it renders an iframe as the content editing area (effectively hiding the textarea).

如果您想提取内容 TinyMCE,您需要使用 TinyMCE API 来执行此操作.您可以使用 getContent() 来检索编辑器的当前内容:

If you want to extract the content TinyMCE you need to use the TinyMCE APIs to do so. You can use getContent() to retrieve the current content of the editor:

https://www.tiny.cloud/docs/api/tinymce/tinymce.editor/#getcontent

例如:

tinymce.activeEditor.getContent(); 

这是一个如何将相邻 DIV 与 TinyMCE 中的内容同步的工作示例:

Here is a working example of how you could sync a neighboring DIV with the content in TinyMCE:

http://fiddle.tinymce.com/HLgaab/5

这篇关于文本框的Javascript值转换为其他html标签(td)onclick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆