【问题标题】:HTML div text to save and display要保存和显示的 HTML div 文本
【发布时间】:2014-02-13 05:07:28
【问题描述】:

以下是我的编辑器代码,当用户按下“显示编辑器文本”按钮时,必须保存 div 标签中的文本,并且必须在同一页面上显示相同的文本。如何在 HTML 中实现这一点?

<!DOCTYPE html>
<html>
<head>
<title>ACE in Action</title>
<style type="text/css" media="screen">
    #editor { 
        position: absolute;
        top: 0;
        right: 0;
        bottom: 7%;
        left: 0;
    }
</style>
</head>
<body>

<div id="editor">
blah blah blah!
</div>

<script src="U:\hyd\code\JS\ace-builds-master\ace-builds-master\src-noconflict\ace.js"       type="text/javascript" charset="utf-8"></script>
<script>
    var editor = ace.edit("editor");
    editor.setTheme("ace/theme/cobalt");
    editor.getSession().setMode("ace/mode/gc");
</script>


<button type= "button" style="position: absolute; left: 10%; bottom: 2%;" id="execute"  onclick="window.open('http://149.77.164.100:8180/FirstServlet/mygeco','_top','resizable=yes')">Click  to execute</button>

<button type= "button" style="position: absolute; left: 25%; bottom: 2%;" id="editortxt"     onclick="showstuff('editor');">Show editor text
</button>

​</body>
</html>

----------------------编辑------------ ---------------------

var edit = ace.edit("editor");
var code = edit.getSession().getValue();
window.open(code, _top);

添加了上面的代码,但没有输出。我想在新窗口中显示代码,然后保存。

【问题讨论】:

  • 定义“已保存”。要将内容回显到页面,您可以使用 javascript 从 ace 获取内容
  • 是的,但是如何在点击时获取 div 标签的内容?你能给我一个代码吗?
  • 第二个结果google我的朋友:stackoverflow.com/a/8976742/143269
  • 谢谢!检查我的编辑,仍然没有输出。

标签: javascript html css ace-editor


【解决方案1】:

无法理解您的编辑器的行为方式

考虑到您想一键保存文本并在

上显示测试

单击此按钮将以下按钮添加到您的 html 中,您的编辑器内容将保存在变量中,编辑器将为空白

    <input type='button' style="position: absolute; left: 20%; bottom: 2%;" id='save' value="Save"/>

单击下面的按钮将显示保存的内容

    <button type= "button" style="position: absolute; left: 25%; bottom: 2%;" id="editortxt"  >Show editor text
    </button>



    <script type='text/javascript'> 
     var StoreEditorContent;  //declare a variable to save Content

      document.getElementById('save').addEventListener("click", SaveText);  // adding event listner for onclick for Saving text

    function SaveText(){

       StoreEditorContent = document.getElementById('editor').innerHTML; // Save the Content into 
       document.getElementById('editor').innerHTML = ""; // to blank the editor Content

    }





      document.getElementById('editortxt').addEventListener("click", ShowText);  // adding event listner for onclick for Saving text

    function ShowText(){

       document.getElementById('editor').innerHTML = StoreEditorContent ; // Display  the Content into  editor

    }

    </script>

【讨论】:

  • 见下半部分,它包含一个事件监听器,用于单击 id="editortxt" 的按钮,单击此按钮时,存储在变量中的内容将显示回编辑器,id="editor" "
  • 10 反对票否。浏览器端 javascript 无权写入客户端计算机,无需禁用大量安全选项
猜你喜欢
  • 1970-01-01
  • 2014-03-02
  • 2013-09-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-06-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多