Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [JavaScript]zatzymac zmienna...
Kamil Pietrzak
post
Post #1





Grupa: Zarejestrowani
Postów: 213
Pomógł: 10
Dołączył: 7.01.2010
Skąd: Lublin

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


witem

  1.  
  2. <script type="text/javascript">
  3. function FormFocusHover(act, id)
  4.  
  5. {
  6. var CSSClass;
  7. CSSClass = document.getElementById(id).className;
  8. if(act == 1)
  9. {document.getElementById(id).className = CSSClass+'_jsHover'; }
  10. if(act == 0)
  11. {document.getElementById(id).className = CSSClass;}
  12.  
  13. }
  14.  


mam taka funkcje js

i wywolanie

  1. <input type="text" name="nick" class="add_coment" id="nickname" onfocus="FormFocusHover(1, 'nickname');" onblur="FormFocusHover(0, 'nickname');" /><br />


jak cos to sens jest taki, ze gdy klawiatura jest na kontrolce to ma inna klase, jest podswietlona

wszystko fajnie, tylko dziala do momentu zdjecia klawiatury
pozniej zmienna CSSClass ma juzi nna wartosc, gdy dam klawuatire jeszcze raz to doda sie nowe '_jsHover' ('_jsHover_jsHover_jsHover_jsHover')
Go to the top of the page
+Quote Post
Pacio
post
Post #2





Grupa: Zarejestrowani
Postów: 105
Pomógł: 27
Dołączył: 30.10.2005
Skąd: Lublin

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


Sprobuj takiej funkcji:
  1. <script type="text/javascript">
  2. function FormFocusHover(act, id) {
  3. var el = document.getElementById(id);
  4. var CSSClass = el.className;
  5. if(act == 1) {
  6. el.className = CSSClass+'_jsHover';
  7. } else {
  8. el.className = el.className.replace('_jsHover', '');
  9. }
  10. }

Przy zdarzeniu onBlur usuwa z atrybutu class tekst '_jsHover', czyli pozostaje poczatkowa klasa.
Go to the top of the page
+Quote Post
Kamil Pietrzak
post
Post #3





Grupa: Zarejestrowani
Postów: 213
Pomógł: 10
Dołączył: 7.01.2010
Skąd: Lublin

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


dzieki, ale okazlao sie, ze mozna w CSS (IMG:style_emoticons/default/biggrin.gif)
a.a:focus

btw. jest jeszcze defaultValue
ale wiadomo... zawsze dookola (IMG:style_emoticons/default/biggrin.gif)
Go to the top of the page
+Quote Post
Pacio
post
Post #4





Grupa: Zarejestrowani
Postów: 105
Pomógł: 27
Dołączył: 30.10.2005
Skąd: Lublin

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


Cytat(Kamil Pietrzak @ 21.01.2010, 10:03:51 ) *
dzieki, ale okazlao sie, ze mozna w CSS (IMG:style_emoticons/default/biggrin.gif)
a.a:focus

Mozna uzyc pseudoklasy :focus, ale nie dziala pod IE. Mozna to obejsc za pomoca :active, ktore dziala w IE tak jak :focus. No, ale znowu w IE nie mozna tego uzyc na elementach innych niz <a></a>, wiec chyba JS w tym wypadku jest najlepszym wyjsciem dla kontrolek formularza.

Ten post edytował Pacio 21.01.2010, 16:44:32
Go to the top of the page
+Quote Post

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

 



RSS Aktualny czas: 27.08.2025 - 17:19