Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/466.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 文本区域中的多个独立区域选择?_Javascript_Jquery_Html - Fatal编程技术网

Javascript 文本区域中的多个独立区域选择?

Javascript 文本区域中的多个独立区域选择?,javascript,jquery,html,Javascript,Jquery,Html,我对编码非常陌生,一直在使用textarea制作文本编辑器组件: 我要做一个函数,它选择一个单词的所有实例。然而,我不知道如何在文本区域中这样做。注意:这不是关于多个插入符号,而是关于多个选择,但是在多个插入符号的实现中的建议将非常感谢。 HTML var lNo=”“; 函数类型(规则){ var div=$(“”{ html:'­;'+rule+'' }).附于(“主体”); } $.fn.selectRange=函数(开始、结束){ 返回此值。每个(函数(){ 如果(末端类型==“

我对编码非常陌生,一直在使用textarea制作文本编辑器组件:

我要做一个函数,它选择一个单词的所有实例。然而,我不知道如何在文本区域中这样做。注意:这不是关于多个插入符号,而是关于多个选择,但是在多个插入符号的实现中的建议将非常感谢。
HTML

var lNo=”“;
函数类型(规则){
var div=$(“”{
html:'­;'+rule+''
}).附于(“主体”);
}
$.fn.selectRange=函数(开始、结束){
返回此值。每个(函数(){
如果(末端类型==“未定义”){
结束=开始;
}
如果(开始==-1){
开始=this.value.length;
}
如果(结束==-1){
end=this.value.length;
}
如果(此.setSelectionRange){
这是focus();
此.setSelectionRange(开始、结束+1);
}else if(this.createTextRange){
var range=this.createTextRange();
范围。塌陷(真);
range.moveEnd('character',end);
range.moveStart('character',start);
range.select();
}
});
};
$.fn.SelectRangeExcludingList=函数(开始、结束){
返回此值。每个(函数(){
如果(末端类型==“未定义”){
结束=开始;
}
如果(开始==-1){
开始=this.value.length;
}
如果(结束==-1){
end=this.value.length;
}
如果(此.setSelectionRange){
这是focus();
此.setSelectionRange(开始、结束+1);
}else if(this.createTextRange){
var range=this.createTextRange();
范围。塌陷(真);
range.moveEnd('character',end);
range.moveStart('character',start);
range.select();
}
});
};
函数getPos(str、substr、index){
var io=str.split(substr,index).join(substr).length;
如果(io>=str.length){
返回-1;
}否则{
返回io;
}
}
功能gutterChildControl(檐槽、文本区域、设置){
if(gotter.childNodes.length!=$(textarea.val().split(“\n”).length){
while(gotter.childNodes.length<$(textarea.val().split(“\n”).length){
var gutterChild=document.createElement(“div”);
gutterChild.className=“gutterChild”
gutterChild.style.height=$(textarea.css('line-height');
var gutterChildLineHeight=$(textarea.css('line-height');
$(gutterChild).css('line-height',gutterChildLineHeight)
gutterChild.style.fontSize=$(textarea.css('font-size');
gutterChild.style.width=“100%”;
gutterChild.style.color=settings.gFontCol;
gutterChild.style.paddingRight=`${settings.gPadding}px`;
gutterChild.style.paddingLeft=`${settings.gPadding}px`;
gutterChild.style.textallign=settings.gFontAlign;
gutterChild.onmouseover=函数(){
gutterChild.style.opacity=“0.75”
}
gutterChild.onmouseleave=函数(){
gutterChild.style.opacity=“1”
}
gutterChild.onclick=函数(){
if(parseInt(gutterChild.innerHTML)!=1){
startPos=getPos($(textarea).val(),“\n”,parseInt(gutterChild.innerHTML)-1)
log(`startPos:${startPos}`);
endPos=getPos($(textarea.val(),“\n”,parseInt(gutterChild.innerHTML))
如果(endPos==-1){
endPos=$(textarea).val().length-1
}
log(`endPos:${endPos}`)
$(文本区域)。选择范围(开始位置、结束位置);
}否则{
startPos=0;
log(`startPos:${startPos}`)
endPos=getPos($(textarea).val(),“\n”,1)
如果(endPos==-1){
endPos=$(textarea).val().length-1
如果(endPos==-1){
endPos=0;
}
}
log(`endPos:${endPos}`)
$(文本区域)。选择范围(开始位置、结束位置);
}
}
排水沟。附属物儿童(gutterChild);
gutterChild.innerHTML=`${gotter.childNodes.length}`
}
while(gotter.childNodes.length>$(textarea.val().split(“\n”).length){
gutter.removeChild(gutter.lastChild)
}
//while(gotter.childNodes.length>$(textarea.val().split(“\n”).length){
//gotter.childNodes.pop;
// }
}
}
功能通风(元件、选项){
常量设置={
塔科尔:“1d252c”,
gCol:“1d252c”,
fSize:“22px”,
gFontCol:“rgba(58,74,88,1)”,
pad:1,
gFontAlign:“居中”,
加上:20,
…选项
}
element.style.display=“flex”;
element.style.flexDirection=“行”;
var gutter=document.createElement(“div”);
var textarea=document.createElement(“textarea”);
gutter.className=“gutter”;
gutter.classList.add(“scrll”)
textarea.className=“ventiEditor”;
textarea.classList.add(“scrll”)
gotter.style.width=“100px”;
gatter.style.height=“100%”;
gotter.style.backgroundColor=settings.gCol;
gutter.style.overflowY=“滚动”
gutter.style.scrollbarWidth=“无”;
injectStyles(“.ground::-webkit滚动条{宽度:0px;}”)
injectStyles(“.ventiEditor{outline:0px!important;-webkit外观:none;}”)
textarea.style.width=“计算(100%-100px)”;
textarea.style.fontSize=settings.fSize;
textarea.style.color=settings.gFontCol;
textarea.style.overflowY=“滚动”;
textarea.style.whiteSpace=“pre”;
textarea.style.resize=“无”;
textarea.style.height=“100%”;
textarea.style.margin=“0px 0px 0px 0px”
textarea.style.border=“0px实心rgb(255255)”
textarea.style.padding=“0”
$(textarea.css('line-height','calc(${2*settings.pad}px+${settings.fSize})`)
textarea.style.backgroundColor=settings.taCol;
textarea.spellcheck=false;
$(textarea).css(“-moz制表符大小”,“4”);
$(textarea).css(“选项卡大小”,“4”)
$('.ventiEditor:focus').css('outline','0px!important'))
$('.ventiEditor:focus').css('-webkit外观','无')
textarea.oninput=函数(){
var gutter=textarea.parentElement.childNodes[0];
gutterChildControl(檐槽、文本区域、设置)