<body> <div class="product" rel="1"> <img class="img_t" src="http://24.img.avito.st/640x480/1406482124.jpg" alt=""> <span class="t_price">Телефон LG </span>цена: <span class="price">6200 </span>количество: <input type="text" size="1" value="0"> <span class="add_t"><img src="http://vstrezhah.ru/p/add.png" alt=""></span> <span class="del_t"><img src="http://www.stitch.su/images/delete_label.gif" alt=""></span> <br> </div> <br> <div class="product" rel="1"> <img class="img_t" src="http://24.img.avito.st/640x480/1406482124.jpg" alt=""> <span class="t_price">Телефон LG </span>цена: <span class="price">6200 </span>количество: <input type="text" size="1" value="0"> <span class="add_t"><img src="http://vstrezhah.ru/p/add.png" alt=""></span> <span class="del_t"><img src="http://www.stitch.su/images/delete_label.gif" alt=""></span> <br> </div> <span id="totalItem"> Итого: <span>0</span> </span> </body> 

And there is jQuery :

 $(document).ready(function(){ var count = 0; $('.add_t').click(function(){ $('input[type=text]').attr('value', count++); }); }); 

The bottom line is that when you click on the plus sign, the number is displayed in the input field in the value value .

I know that this is done using this , but I do not know how, tell me, please.


UPD

http://jsfiddle.net/2kygh3ba/7/

If this is correct, then how can I transfer this to a php processor?

    2 answers 2

     $(document).ready(function () { // Из-за того, что переменная у вас была объявлена вне функции, // ее значение наращивалось при клике на любой .add_t, // без привязки к продукту // var count = 0; $('.add_t').click(function () { // получаем родительский блок .product var product = $(this).closest('.product'); // ищем в родительском блоке нужный input var product_input = product.find('input[type=text]'); // Получаем предыдущее количество товара в input // и преобразуем в целочисленный тип var previous_product_count = parseInt(product_input.val(), 10); // Если оно не задано, ставим количество равным 1 // По кнопке все-таки кликнули. if (!previous_product_count) { // Из-за того что у вас изначально count был равен 0 // После первого клика на кнопку ничего не происходило var current_count = 1; } else { // Увеличиваем количество товара на 1 var current_count = previous_product_count + 1; } // Записываем новое количество товара product_input.val(current_count); }); }); 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <div class="product" rel="1"> <img class="img_t" src="http://24.img.avito.st/640x480/1406482124.jpg" alt="" /> <span class="t_price">Телефон LG </span>цена: <span class="price">6200 </span>колличество: <input type="text" size="1" value="0"> <span class="add_t"><img src="http://vstrezhah.ru/p/add.png" alt=""/></span> <span class="del_t"><img src="http://www.stitch.su/images/delete_label.gif" alt=""/></span> <br/> </div> <br/> <div class="product" rel="1"> <img class="img_t" src="http://24.img.avito.st/640x480/1406482124.jpg" alt="" /> <span class="t_price">Телефон LG </span>цена: <span class="price">6200 </span>колличество: <input type="text" size="1" value="0"> <span class="add_t"><img src="http://vstrezhah.ru/p/add.png" alt=""/></span> <span class="del_t"><img src="http://www.stitch.su/images/delete_label.gif" alt=""/></span> <br/> </div> <span id="totalItem"> Итого: <span>0</span> </span> 

    See an example

    • @TheDoctor, please do not change my answer. After your edits, the built-in example does not work. - VenZell
    • Missed, apparently, now works. The jsFiddle code must be given as a secondary example, please insert the code through the editor. - user31688
    • @TheDoctor I also ask you not to delete my explanations from the answer. This is at least impolite. I myself decide what should be included in the answer, and what is not. I specifically gave extended explanations for the beginner. - VenZell

    You can try this:

     $(document).ready(function(){ var count = 0; $('.add_t').click(function(){ var input = $(this).parent().find('input[type=text]'); var inputValue = input.val(); input.val(++inputValue); //$('input[type=text]').attr('value', count++); }); }); 
     <div class="product" rel="1"> <img class="img_t" src="http://24.img.avito.st/640x480/1406482124.jpg" alt=""> <span class="t_price">Телефон LG </span>цена: <span class="price">6200 </span>колличество: <input type="text" size="1" value="0"> <span class="add_t"><img src="http://vstrezhah.ru/p/add.png" alt=""></span> <span class="del_t"><img src="http://www.stitch.su/images/delete_label.gif" alt=""></span> <br> </div> <br> <div class="product" rel="1"> <img class="img_t" src="http://24.img.avito.st/640x480/1406482124.jpg" alt=""> <span class="t_price">Телефон LG </span>цена: <span class="price">6200 </span>колличество: <input type="text" size="1" value="0"> <span class="add_t"><img src="http://vstrezhah.ru/p/add.png" alt=""></span> <span class="del_t"><img src="http://www.stitch.su/images/delete_label.gif" alt=""></span> <br> </div> <span id="totalItem"> Итого: <span>0</span> </span> 

    Jsfiddle