mercredi 29 juin 2016

How can i change `keyword` color on runtime in `textarea` or `textbox`? Javascript


I have a textarea i want that when i type keyword like var and press SPACEbutton then it's color will be blue on runtime.I defind many keyword my self.Not on button click its will be on runtime.How can i do this?Thanks.And i also want this textarea text in codebehind.I'm working in ASP.NET C# environment.Same like SQL-QUERY-EDITOR. Here is my code :

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" runat="server">
var codeInput = document.getElementsByTagName("textarea");
var keywords = new Array("var", "if");
function checkHighlight(){
var codeInput1 = codeInput[0].value;
if(codeInput1 === keywords[0]){
 keywords[0].indexOf(codeInput1).className = "JSfunctions";
}
}
</script>
<style type="text/css" runat="server">
    #JScodeinputbox{font-family:Arial;}
  #JScodeoutputbox{}
    .JSfunctions{color:blue;}
</style>
 </head>
 <body>
 <form id="form1" runat="server">
 <div>
 <textarea id="JScodeinputbox" wrap="logical" rows="30" cols="70" onkeyup="checkHighlight();"></textarea>
</div>
</form>
</body>
</html>

Aucun commentaire:

Enregistrer un commentaire