gpt4 book ai didi

javascript - 自己尝试一下文本编辑器

转载 作者:行者123 更新时间:2023-11-28 20:31:34 25 4
gpt4 key购买 nike

我如何创建一个像 W3School's try it yourself editor? 这样的在线编辑器

我已经尝试过使用 JQuery 的 keyup();功能,但我似乎无法让它工作。这是我到目前为止所拥有的:

<!DOCTYPE html>
<html lang="en">
<head>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.1.1.min.js"></script>

<script type="text/javascript">
$("#idinput").keyup( function() {
$("#idoutput").html($("#idinput").val());
} );
</script>
</head>
<body>


<textarea id="idinput"></textarea>
<br>
<div id="idoutput"></div>
</body>
</html>

如果我犯了一些简单的错误,请告诉我。我对 JQuery 很陌生,这是迄今为止我用它编写的最复杂的东西。

我意识到以前可能有人问过这个问题,但其他解决方案都不起作用。提前致谢。

最佳答案

您的脚本在 textareadiv 存在之前执行。尝试使用以下代码包装您的代码,以延迟执行,直到文档准备就绪。

$(document).ready(function() {
// Your code here.
});

关于javascript - 自己尝试一下文本编辑器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16267817/

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