Меню Рубрики

Установка курсора в textarea

Как установить курсор внутри textarea с помощью jquery?

Мне нужно чтобы скрипт по нажатию кнопки устанавливал курсор в textarea в позицию слова которое записано в поле поиска

но курсор не устанавливается в нужное место

DevMan: странно но я сейчас попробовал запихнуть тот текст который у меня в textarea прямо в ваш пример — на том вашем сайте

и ситуация повтрилась — с первого нажатия поиск не сработал

текст по которому я ищу вот такой

html <
color: #222;
font-size: 1em;
line-height: 1.4;
background: url(../img/1.jpg);
>

::-moz-selection <
background: #b3d4fc;
text-shadow: none;
>

::selection <
background: #b3d4fc;
text-shadow: none;
>

hr <
display: block;
height: 1px;
border: 0;
border-top: 1px solid #ccc;
margin: 1em 0;
padding: 0;
>

audio,
canvas,
iframe,
img,
svg,
video <
vertical-align: middle;
>

fieldset <
border: 0;
margin: 0;
padding: 0;
>

.browserupgrade <
margin: 0.2em 0;
background: #ccc;
color: #000;
padding: 0.2em 0;
>

.zag2 <
font-size: 1.2em;
font-weight: bold;
>

>
a <
color: black;
>
.header <
width: 1000px;
margin: 0 auto;
height: 100px;
padding: 10px;
-o-background-size: 100% 100%; -webkit-background-size: 100% 100%; -khtml-background-size: 100% 100%; background-size: 100% 100%;
background: -moz-linear-gradient(top,deepskyblue,#efefef);
background: -webkit-gradient(linear, left top, left bottom, from(deepskyblue), to(#efefef));
filter: prog ,startColorstr=deepskyblue,endColorstr=#efefef,GradientType=0); zoom: 1;
background: linear-gradient(top,deepskyblue,#efefef);
background-clip: border-box; -moz-background-clip: border; -webkit-background-clip: border-box;
background-origin: border-box; -moz-background-origin: border; -webkit-background-origin: border-box;
>
.logo <
position: relative;
top: 5px;
left: 35px;
height:120px;
display: inline;
>
.header h1 <
position: relative;
top: 3px;
left: 150px;
display: inline;
font-family: ‘Monotype corsiva’;
color: black;
text-shadow: 1px 1px 1px green;
font-size: 2.5em;
>
.content <
width: 1000px;
min-height: 900px;
margin: 0 auto;
padding: 10px;
background-color: #efefef;
>
.menu <
margin-left: -20px;
margin-top: 30px;
width: 260px;
padding: 10px;
padding-right: 20px;
display: inline-block;
>
.foto <
width: 200px;
margin-left:40px;
border:3px solid violet;
>
.menu ul <
list-style: none;
>
.clr <
text-indent: 0px;
>
.clr span:nth-child(1) .clr span:nth-child(2) .clr span:nth-child(3) .clr span:nth-child(4) .clr span:nth-child(5) .clr span:nth-child(6) .clr span:nth-child(7) .clr span:nth-child(8) .clr span:nth-child(9) .clr span:nth-child(10) .clr span:nth-child(11) .clr span:nth-child(12) .clr span:nth-child(13) .clr span:nth-child(14) .clr span:nth-child(15) .clr span:nth-child(16) .clr span:nth-child(17) .clr span:nth-child(18) .clr span:nth-child(19) .clr span:nth-child(20) .clr span:nth-child(21) .clr span:nth-child(22) .clr span:nth-child(23) .clr span:nth-child(24) .clr span:nth-child(25) .clr span:nth-child(26) .clr span:nth-child(27) .clr span:nth-child(28) .menu ul li a <
display: block;
width: 185px;
padding-left: 10px;
padding-right: 10px;
height: 35px;
line-height: 35px;
-o-background-size: 100% 100%; -webkit-background-size: 100% 100%; -khtml-background-size: 100% 100%; background-size: 100% 100%;
background: -moz-linear-gradient(top,#fff,violet);
background: -webkit-gradient(linear, left top, left bottom, from(white), to(violet));
filter: prog ,startColorstr=#ffffff,endColorstr=violet,GradientType=0); zoom: 1;
background: linear-gradient(top,#fff,violet);
background-clip: border-box; -moz-background-clip: border; -webkit-background-clip: border-box;
background-origin: border-box; -moz-background-origin: border; -webkit-background-origin: border-box;
text-align: left;
color: black;
margin-bottom: 5px;
text-decoration: none;
font-weight: bold;
font-size: 0.9em;
font-family: «Arial»;
>
.menu ul li a:hover <
-o-background-size: 100% 100%; -webkit-background-size: 100% 100%; -khtml-background-size: 100% 100%; background-size: 100% 100%;
background: -moz-linear-gradient(top,#fff,#89f81f);
background: -webkit-gradient(linear, left top, left bottom, from(white), to(#89f81f));
filter: prog ,startColorstr=#ffffff,endColorstr=#89f81f,GradientType=0); zoom: 1;
background: linear-gradient(top,#fff,#89f81f);
background-clip: border-box; -moz-background-clip: border; -webkit-background-clip: border-box;
background-origin: border-box; -moz-background-origin: border; -webkit-background-origin: border-box;
>
.main <
width: 680px;
padding: 10px;
display: inline-block;
vertical-align: top;
text-align: justify;
font-family: ‘Sans’;
white-space: pre-wrap;
white-space: pre;
white-space: pre-line;
white-space: -moz-pre-wrap !important;
white-space: -hp-pre-wrap;
white-space: -o-pre-wrap;
white-space: -pre-wrap;
word-wrap: break-word;
-webkit-font-smoothing: antialiased;
>
a <
color: darkgreen;
text-decoration: none;
>
.footer <
width: 1000px;
height: 50px;
line-height: 50px;
margin: 0 auto;
padding: 10px;
-o-background-size: 100% 100%; -webkit-background-size: 100% 100%; -khtml-background-size: 100% 100%; background-size: 100% 100%;
background: -moz-linear-gradient(top,#efefef,lightgreen);
background: -webkit-gradient(linear, left top, left bottom, from(#efefef), to(lightgreen));
filter: prog ,startColorstr=#efefef,endColorstr=lightgreen,GradientType=0); zoom: 1;
background: linear-gradient(top,#efefef,lightgreen);
background-clip: border-box; -moz-background-clip: border; -webkit-background-clip: border-box;
background-origin: border-box; -moz-background-origin: border; -webkit-background-origin: border-box;
text-align: center;
color: black;
font-weight: bold;
font-size: 0.9em;
font-family: «Arial»;
>
.anons <
display: block;
margin-top: 20px;
>
input, textarea <
width: 600px;
>

Читайте также:  Установка и конфигурация linux

media only screen and (max-width: 800px) <
.header <
width: 90%;
height: 50px;
>
.logo <
display: none;
>
.foto <
width: 90%;
border:3px solid violet;
>
.header h1 <
top: 5px;
left: 10px;
text-shadow: none;
font-size: 1.7em;
>
img <
max-width: 100%;
>
.content <
width: 90%;
>
.menu <
padding: 5px;
padding-right: 0px;
width: 90%;
text-align: center;
>
.menu ul li a <
width: 100%;
>
.main <
width: 90%;
>
.footer <
width: 90%;
height: 50px;
line-height: 50px;
>
input, textarea <
width: 80%;
>
>

media print,
(-o-min-device-pixel-ratio: 5/4),
(-webkit-min-device-pixel-ratio: 1.25),
(min-resolution: 120dpi) <

.hidden <
display: none !important;
visibility: hidden;
>

.visuallyhidden <
border: 0;
clip: rect(0 0 0 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
>

.visuallyhidden.focusable:active,
.visuallyhidden.focusable:focus <
clip: auto;
height: auto;
margin: 0;
overflow: visible;
position: static;
width: auto;
>

.invisible <
visibility: hidden;
>

.clearfix:before,
.clearfix:after <
content: » «;
display: table;
>

media print <
*,
*:before,
*:after <
background: transparent !important;
color: #000 !important;
box-shadow: none !important;
text-shadow: none !important;
>

a,
a:visited <
text-decoration: underline;
>

a[href]:after <
content: » (» attr(href) «)»;
>

abbr[title]:after <
content: » (» attr(title) «)»;
>

pre,
blockquote <
border: 1px solid #999;
page-break-inside: avoid;
>

thead <
display: table-header-group;
>

tr,
img <
page-break-inside: avoid;
>

img <
max-width: 100% !important;
>

при этом я пытаюсь искать например слово anons

источник

Как установить курсор внутри textarea с помощью jquery?

Мне нужно чтобы скрипт по нажатию кнопки устанавливал курсор в textarea в позицию слова которое записано в поле поиска

но курсор не устанавливается в нужное место

DevMan: странно но я сейчас попробовал запихнуть тот текст который у меня в textarea прямо в ваш пример — на том вашем сайте

и ситуация повтрилась — с первого нажатия поиск не сработал

текст по которому я ищу вот такой

Читайте также:  Установка коронки на зуб без удаления

html <
color: #222;
font-size: 1em;
line-height: 1.4;
background: url(../img/1.jpg);
>

::-moz-selection <
background: #b3d4fc;
text-shadow: none;
>

::selection <
background: #b3d4fc;
text-shadow: none;
>

hr <
display: block;
height: 1px;
border: 0;
border-top: 1px solid #ccc;
margin: 1em 0;
padding: 0;
>

audio,
canvas,
iframe,
img,
svg,
video <
vertical-align: middle;
>

fieldset <
border: 0;
margin: 0;
padding: 0;
>

.browserupgrade <
margin: 0.2em 0;
background: #ccc;
color: #000;
padding: 0.2em 0;
>

.zag2 <
font-size: 1.2em;
font-weight: bold;
>

>
a <
color: black;
>
.header <
width: 1000px;
margin: 0 auto;
height: 100px;
padding: 10px;
-o-background-size: 100% 100%; -webkit-background-size: 100% 100%; -khtml-background-size: 100% 100%; background-size: 100% 100%;
background: -moz-linear-gradient(top,deepskyblue,#efefef);
background: -webkit-gradient(linear, left top, left bottom, from(deepskyblue), to(#efefef));
filter: prog ,startColorstr=deepskyblue,endColorstr=#efefef,GradientType=0); zoom: 1;
background: linear-gradient(top,deepskyblue,#efefef);
background-clip: border-box; -moz-background-clip: border; -webkit-background-clip: border-box;
background-origin: border-box; -moz-background-origin: border; -webkit-background-origin: border-box;
>
.logo <
position: relative;
top: 5px;
left: 35px;
height:120px;
display: inline;
>
.header h1 <
position: relative;
top: 3px;
left: 150px;
display: inline;
font-family: ‘Monotype corsiva’;
color: black;
text-shadow: 1px 1px 1px green;
font-size: 2.5em;
>
.content <
width: 1000px;
min-height: 900px;
margin: 0 auto;
padding: 10px;
background-color: #efefef;
>
.menu <
margin-left: -20px;
margin-top: 30px;
width: 260px;
padding: 10px;
padding-right: 20px;
display: inline-block;
>
.foto <
width: 200px;
margin-left:40px;
border:3px solid violet;
>
.menu ul <
list-style: none;
>
.clr <
text-indent: 0px;
>
.clr span:nth-child(1) .clr span:nth-child(2) .clr span:nth-child(3) .clr span:nth-child(4) .clr span:nth-child(5) .clr span:nth-child(6) .clr span:nth-child(7) .clr span:nth-child(8) .clr span:nth-child(9) .clr span:nth-child(10) .clr span:nth-child(11) .clr span:nth-child(12) .clr span:nth-child(13) .clr span:nth-child(14) .clr span:nth-child(15) .clr span:nth-child(16) .clr span:nth-child(17) .clr span:nth-child(18) .clr span:nth-child(19) .clr span:nth-child(20) .clr span:nth-child(21) .clr span:nth-child(22) .clr span:nth-child(23) .clr span:nth-child(24) .clr span:nth-child(25) .clr span:nth-child(26) .clr span:nth-child(27) .clr span:nth-child(28) .menu ul li a <
display: block;
width: 185px;
padding-left: 10px;
padding-right: 10px;
height: 35px;
line-height: 35px;
-o-background-size: 100% 100%; -webkit-background-size: 100% 100%; -khtml-background-size: 100% 100%; background-size: 100% 100%;
background: -moz-linear-gradient(top,#fff,violet);
background: -webkit-gradient(linear, left top, left bottom, from(white), to(violet));
filter: prog ,startColorstr=#ffffff,endColorstr=violet,GradientType=0); zoom: 1;
background: linear-gradient(top,#fff,violet);
background-clip: border-box; -moz-background-clip: border; -webkit-background-clip: border-box;
background-origin: border-box; -moz-background-origin: border; -webkit-background-origin: border-box;
text-align: left;
color: black;
margin-bottom: 5px;
text-decoration: none;
font-weight: bold;
font-size: 0.9em;
font-family: «Arial»;
>
.menu ul li a:hover <
-o-background-size: 100% 100%; -webkit-background-size: 100% 100%; -khtml-background-size: 100% 100%; background-size: 100% 100%;
background: -moz-linear-gradient(top,#fff,#89f81f);
background: -webkit-gradient(linear, left top, left bottom, from(white), to(#89f81f));
filter: prog ,startColorstr=#ffffff,endColorstr=#89f81f,GradientType=0); zoom: 1;
background: linear-gradient(top,#fff,#89f81f);
background-clip: border-box; -moz-background-clip: border; -webkit-background-clip: border-box;
background-origin: border-box; -moz-background-origin: border; -webkit-background-origin: border-box;
>
.main <
width: 680px;
padding: 10px;
display: inline-block;
vertical-align: top;
text-align: justify;
font-family: ‘Sans’;
white-space: pre-wrap;
white-space: pre;
white-space: pre-line;
white-space: -moz-pre-wrap !important;
white-space: -hp-pre-wrap;
white-space: -o-pre-wrap;
white-space: -pre-wrap;
word-wrap: break-word;
-webkit-font-smoothing: antialiased;
>
a <
color: darkgreen;
text-decoration: none;
>
.footer <
width: 1000px;
height: 50px;
line-height: 50px;
margin: 0 auto;
padding: 10px;
-o-background-size: 100% 100%; -webkit-background-size: 100% 100%; -khtml-background-size: 100% 100%; background-size: 100% 100%;
background: -moz-linear-gradient(top,#efefef,lightgreen);
background: -webkit-gradient(linear, left top, left bottom, from(#efefef), to(lightgreen));
filter: prog ,startColorstr=#efefef,endColorstr=lightgreen,GradientType=0); zoom: 1;
background: linear-gradient(top,#efefef,lightgreen);
background-clip: border-box; -moz-background-clip: border; -webkit-background-clip: border-box;
background-origin: border-box; -moz-background-origin: border; -webkit-background-origin: border-box;
text-align: center;
color: black;
font-weight: bold;
font-size: 0.9em;
font-family: «Arial»;
>
.anons <
display: block;
margin-top: 20px;
>
input, textarea <
width: 600px;
>

Читайте также:  Установка автовыключателя в электросчетчике

media only screen and (max-width: 800px) <
.header <
width: 90%;
height: 50px;
>
.logo <
display: none;
>
.foto <
width: 90%;
border:3px solid violet;
>
.header h1 <
top: 5px;
left: 10px;
text-shadow: none;
font-size: 1.7em;
>
img <
max-width: 100%;
>
.content <
width: 90%;
>
.menu <
padding: 5px;
padding-right: 0px;
width: 90%;
text-align: center;
>
.menu ul li a <
width: 100%;
>
.main <
width: 90%;
>
.footer <
width: 90%;
height: 50px;
line-height: 50px;
>
input, textarea <
width: 80%;
>
>

media print,
(-o-min-device-pixel-ratio: 5/4),
(-webkit-min-device-pixel-ratio: 1.25),
(min-resolution: 120dpi) <

.hidden <
display: none !important;
visibility: hidden;
>

.visuallyhidden <
border: 0;
clip: rect(0 0 0 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
>

.visuallyhidden.focusable:active,
.visuallyhidden.focusable:focus <
clip: auto;
height: auto;
margin: 0;
overflow: visible;
position: static;
width: auto;
>

.invisible <
visibility: hidden;
>

.clearfix:before,
.clearfix:after <
content: » «;
display: table;
>

media print <
*,
*:before,
*:after <
background: transparent !important;
color: #000 !important;
box-shadow: none !important;
text-shadow: none !important;
>

a,
a:visited <
text-decoration: underline;
>

a[href]:after <
content: » (» attr(href) «)»;
>

abbr[title]:after <
content: » (» attr(title) «)»;
>

pre,
blockquote <
border: 1px solid #999;
page-break-inside: avoid;
>

thead <
display: table-header-group;
>

tr,
img <
page-break-inside: avoid;
>

img <
max-width: 100% !important;
>

при этом я пытаюсь искать например слово anons

источник

Добавить комментарий

Adblock
detector