Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Jak w juery za pomocą linków dynamicznie zmienić zawartość value w input?
marcus755
post
Post #1





Grupa: Zarejestrowani
Postów: 158
Pomógł: 1
Dołączył: 6.12.2012

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


Hej wszystkim:-)

Jak zrobić w jquery?
żeby gdy klikamy link o id="test1" - value zmienia się o +1,
a gdy klikamy link o id="test0", to zmniejsza się o -1, a gdy mamy w value=0 (to nie zmniejsza mniej niż 0)

Poniżej skrypt, który napisałem, ale nie działa...

  1.  
  2. <a href="#" id="test0"></a>
  3. <label>Ilość</label>
  4. <input name="0" type="text" value="0" id="test11">
  5. <a href="#" id="test1"></a>
  6.  
  7. var n = 0;
  8. $("#test1").click(function (e) {
  9. e.preventDefault(); // prevent the default action
  10. e.stopPropagation; // stop the click from bubbling
  11. var text = $(this).text();
  12. $("input").find("test11").val(++n);
  13. });
  14.  
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
marcus755
post
Post #2





Grupa: Zarejestrowani
Postów: 158
Pomógł: 1
Dołączył: 6.12.2012

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


  1. <a href="#" id="test0"></a>
  2. <label>Ilość</label>
  3. <input name="0" type="text" value="0" id="test11">
  4. <a href="#" id="test1"></a>
  5.  
  6. var n = 0;
  7. $(document).ready(function(){
  8. $("#test1").click(function(){
  9. $("input:text#test11").val(++n);
  10. });
  11. $("#test0").click(function(){
  12. $("input:text#test11").val(--n);
  13.  
  14. if (
  15. $("input:text#test11").val(n=0);
  16. );
  17. return true;
  18.  
  19. });
  20. });


ale nie działa nie wiem, jak zrobić, aby nie wrzucał liczb mniejszych niż 0.

Ten post edytował marcus755 10.06.2013, 14:39:22
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: 30.12.2025 - 00:35