Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JavaScript][HTML]przesunięcie kusrora na poczatek inputa
Qss
post 5.07.2013, 19:36:25
Post #1





Grupa: Zarejestrowani
Postów: 141
Pomógł: 7
Dołączył: 22.02.2009

Ostrzeżenie: (0%)
-----


Witam,
Jak przesunąć cursor na początek inputa tzn.

Mamy taki input
  1. <input type="text" name="email" value="Adres e-mail" />


jeśli w niego kline to kursor pojawi sie po value i będę mógł coś dopisać na końcu czyli ostatecznie wyjdzie: Adres e-maildfdf
a chodzi mi o to żeby po kliknieciu w input cursor był przed napisem z value i pisząc dodaje przedrostek (dopisuje coś na początku) i wtedy vy wyszło tak: sdsAdres e-mail
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 2)
Greg0
post 5.07.2013, 19:59:03
Post #2





Grupa: Zarejestrowani
Postów: 264
Pomógł: 54
Dołączył: 31.08.2007
Skąd: Tychy

Ostrzeżenie: (0%)
-----


zdarzenie onFocus
Kod
onFocus="this.value=null"
Go to the top of the page
+Quote Post
gr56
post 5.07.2013, 20:17:31
Post #3





Grupa: Zarejestrowani
Postów: 77
Pomógł: 15
Dołączył: 19.11.2011

Ostrzeżenie: (0%)
-----


Cytat(Greg0 @ 5.07.2013, 20:59:03 ) *
zdarzenie onFocus
Kod
onFocus="this.value=null"

Ten kod usunie tekst z inputa.

Użyj poniższej funkcji aby ustawić pozycje kursora.
Kod
function setCaretPosition(elemId, caretPos) {
    var elem = document.getElementById(elemId);

    if(elem != null) {
        if(elem.createTextRange) {
            var range = elem.createTextRange();
            range.move('character', caretPos);
            range.select();
        }
        else {
            if(elem.selectionStart) {
                elem.focus();
                elem.setSelectionRange(caretPos, caretPos);
            }
            else
                elem.focus();
        }
    }
}
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 18.07.2025 - 02:33