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%)
-----


Kod
<a href="#" id="test0"></a>
<label>Ilość</label>
<input name="0" type="text" value="0" id="test11">
<a href="#" id="test1"></a>

<script>
var n = 0;
$(document).ready(function(){
  $("#test1").click(function(){
    $("input:text#test11").val(++n);
  });
  $("#test0").click(function(){
    $("('input:text#test11').val(++n);").val(-1);
  });
});
</script>


Działa mi dodawanie.
A jak zrobić, żeby mi odejmował bieżący stan value?
(np. mam w danym momencie w input value=5, klikając w link o id="test0", zmniejsza mi się o 1, aż do wartości wyjściowej value=0)
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:34