gpt4 book ai didi

javascript - 要保存和显示的 HTML div 文本

转载 作者:行者123 更新时间:2023-11-28 11:16:05 24 4
gpt4 key购买 nike

以下是我的编辑器代码,当用户按下“显示编辑器文本”按钮时,必须保存 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);

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

最佳答案

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

考虑到你想在一个按钮上保存文本,点击并显示测试后者

将下面的按钮添加到您的 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>

关于javascript - 要保存和显示的 HTML div 文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21745712/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com