私は次のものを持っていますdiv
:
<div id="query" style="width:500px; height:200px;border:1px solid black"
spellcheck="false" contenteditable="true"></div>
クライアントがSQL
クエリを記述できる場所。Space私がやろうとしていたのは、クライアントがaを押した直後に入力した単語をラップし、入力した単語に応じてspan
このスパンを特定することです。class
例
クライアントタイプの場合、select
この選択した単語をdivで次のようにラップする必要があります。
<span class='select'> SELECT </span> <span> emp_name </span>
CSS
.select{color:blue ;text-transform:uppercase;}
それは何をするかと非常に似てjsFiddle
います。どうすればこれを達成できますか?
これが私がこれまでに試したことです:jsFiddle
$(function(){
$('div').focus() ;
$('div').keyup(function(e){
//console.log(e.keyCode) ;
if(e.keyCode == 32){
var txt = $('div').text() ;
var x = 'SELECT' ;
$('div:contains("'+x+'")').wrap("<span style='color:blue ;
text-transform:uppercase;'>") ;
if(txt == 'SELECT'){
console.log('found') ; // why This Doesn't do any thing ?
}
}
});
});