Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [jquery] dynamiczny formularz i focus()
daggoth
post
Post #1





Grupa: Zarejestrowani
Postów: 13
Pomógł: 1
Dołączył: 19.01.2014

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


Witajcie drodzy pehapowicze (IMG:style_emoticons/default/smile.gif)
Raczkuję w temacie jQuery więc zwracam się do was z prośbą o pomoc.

Wymarzyło mi się, aby gdy użytkownik kliknie w ostatniego selecta by coś wklupać, zaraz pod nim wskoczy nowy select i tak w nieskończoność (IMG:style_emoticons/default/smile.gif)
Znalazłem coś w interneciku i przerobiłem pod metodę focus(). Działa ale tylko na pierwszym selekcie (tak jakby ciągle stał na jednej wartości) Ma ktoś jakiś pomysł (IMG:style_emoticons/default/questionmark.gif)

Kod
  1.  
  2. <div class="container">
  3. <div class="row">
  4. <input type="text" id="count" name="count" value="1" />
  5. <div class="control-group" id="fields">
  6. <label class="control-label" for="field1">Nice Multiple Form Fields</label>
  7. <div class="controls" id="profs">
  8. <div class="input-append">
  9. <input autocomplete="off" class="span3" id="field1" name="prof1" type="text" placeholder="Type something (it has typeahead too)" data-provide="typeahead" data-items="8" data-source='["Aardvark","Beatlejuice","Capricorn","Deathmaul","Epic"]'/><button id="b1" class="btn btn-info add-more" type="button">+</button>
  10. </div>
  11. <br>
  12. <small>Press + to add another form field :)</small>
  13. </div>
  14. </div>
  15. </div>
  16. </div>
  17. <script src="http://code.jquery.com/jquery-1.9.0.js"></script>
  18. <script src="http://code.jquery.com/jquery-migrate-1.2.1.js"></script>
  19. <script>
  20. $(document).ready(function(){
  21. var next = 1;
  22. $("#field"+next).focus(function(e){
  23. e.preventDefault();
  24. var addto = "#field" + next;
  25. next = next + 1;
  26. var newIn = '<br /><br /><input autocomplete="off" class="span3" id="field' + next + '" name="field' + next + '" type="text" data-provide="typeahead" data-items="8">';
  27. var newInput = $(newIn);
  28. $(addto).after(newInput);
  29. $("#field" + next).attr('data-source',$(addto).attr('data-source'));
  30. $("#count").val(next);
  31. });
  32. });
  33.  
  34. </script>


Edit:
Późna pora, zapomniałem linka:
tu to działa (IMG:style_emoticons/default/smile.gif)

http://jsbin.com/EBUMoKa/1/

Ten post edytował daggoth 20.01.2014, 23:38:52
Go to the top of the page
+Quote Post

Posty w temacie


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: 7.10.2025 - 10:04