textarea中的Highlight.js [英] Highlight.js in textarea

查看:350
本文介绍了textarea中的Highlight.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我一直在努力在文本区域中使用Highlight.js,因为显然这是行不通的:

So i have been struggeling to use highlight.js in a text area since obviously this doesn't work:

<!DOCTYPE html>
<html>
<head>
<title>Hello World</title>
<link rel="stylesheet" href="styles/default.css">
<script src="highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
</head>
<body>
<form>
    JavaScript Injection: <br> 
<pre>
<code>
<textarea name="js_execute" cols="50" rows="10" "></textarea>
</code>
</pre>
<input type="button" name="Inject_Execute_Button" value = "Inject" onclick="executeJS()" >
</form>

<script type="text/javascript">
 function executeJS()
 {
     alert("Wohoo");
 }
</script>


<style type ="text/css">

</style>
</body>
</html>

我很确定对此有一个简单的答案,所以我不会太详细地解释它,但是最后我希望将代码键入到JavaScript中突出显示的文本区域中.

I'm pretty sure there's an easy answer to this so i won't explain it in too detail but at the end i would prefer to have code typed into the textarea highlighted in JavaScript.

推荐答案

您可能想看看 http://ace .c9.io/,突出显示语法,但专门针对编辑.

You might want to look at http://ace.c9.io/, which does syntax highlighting, but is specifically aimed at editing.

但是请注意,它也没有使用textarea,可能是由于@isagalaev提到的相同原因.

Note however that it does not use textarea either, probably for the same reasons mentioned by @isagalaev.

这篇关于textarea中的Highlight.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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