Autor | Zpráva | ||
---|---|---|---|
lopikol Profil |
#1 · Zasláno: 11. 1. 2012, 23:10:25
Mám tento kod a budu vděčný, když mi do něj někdo doplní kod, který zajístí, že se za doplněný text přidá kurzor, tak abych mohl ihned psát a nemusel klikat myší do textarey.
$("a.react").click(function(){ var nick = $(this).attr("data-nick"); var textarea = "textarea[name=text]" var value = $(textarea).val(); if(value) { $(textarea).val(value + "\n\n@" + nick + ":"); }else{ $(textarea).val("@" + nick + ":"); } }); |
||
Kcko Profil |
#2 · Zasláno: 11. 1. 2012, 23:30:45
$(textarea).focus(); |
||
lopikol Profil |
#3 · Zasláno: 11. 1. 2012, 23:51:32
Kcko:
Zkusil jsem, ale nijak to nepomohlo. |
||
Časová prodleva: 1 měsíc
|
|||
CreebyCZ Profil |
#4 · Zasláno: 17. 2. 2012, 02:14:37
Budeš potřebovat tyto funkce:
function setSelectionRange(input, selectionStart, selectionEnd) { if (input.setSelectionRange) { input.focus(); input.setSelectionRange(selectionStart, selectionEnd); } else if (input.createTextRange) { var range = input.createTextRange(); range.collapse(true); range.moveEnd('character', selectionEnd); range.moveStart('character', selectionStart); range.select(); } } function setCaretToPos (input, pos) { setSelectionRange(input, pos, pos); } Kurzor umístíš na konec vloženého textu takto: $("a.react").click(function(){ var nick = $(this).attr("data-nick"); var textarea = "textarea[name=text]" var value = $(textarea).val(); if(value) { $(textarea).val(value + "\n\n@" + nick + ":"); }else{ $(textarea).val("@" + nick + ":"); } setCaretToPos($(textarea), $(textarea).val().length); }); |
||
Časová prodleva: 12 let
|
0