MixPetrov,
<!DOCTYPE html> <html> <head> <title>Untitled</title> <meta charset="utf-8"> <style type="text/css"> </style> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css"> <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script> <script> $ (function () { function mathC(){ var nmb = +this.dataset.nmb; var ns = +this.value; ns = ns || 0; ns = Math.ceil(ns/nmb)*nmb; this.value = ns } var timer; $('.quantity_cart [type="text"]').on("input", function() { window.clearTimeout(timer); timer = window.setTimeout(mathC.bind(this), 1200) }) }); </script> </head> <body class="quantity_cart"> <input name="1" size="2" value="1" type="text" data-nmb="3"> <input name="1" size="2" value="1" type="text" data-nmb="3"> </body> </html> |
Не работает
А можно ли к функции подключить таймер без $('.quantity_cart [type="text"]').on("input", function() $ (function () { function mathC(){ var nmb = +($('input[name=\'' + product_id + '\']').val().dataset.nmb); // var ns = +this.value; //ns = ns || 0; //ns = Math.ceil(ns/nmb)*nmb; //this.value = ns var ns = +$('input[name=\'' + product_id + '\']').val(); ns = ns || 0; ns = Math.ceil(ns/nmb)*nmb; $('input[name=\'' + product_id + '\']').val(ns) } var timer; $('.quantity_cart [type="text"]').on("input", function() { window.clearTimeout(timer); timer = window.setTimeout(mathC.bind(this), 1200) }) }); |
MixPetrov,
пас |
Подскажите в чем делаю ошибку?
$ (function () { function mathC(){ var nmb = +($('input[name=\'' + product_id + '\']').val().dataset.nmb); // var ns = +this.value; //ns = ns || 0; //ns = Math.ceil(ns/nmb)*nmb; //this.value = ns var ns = +$('input[name=\'' + product_id + '\']').val(); ns = ns || 0; ns = Math.ceil(ns/nmb)*nmb; $('input[name=\'' + product_id + '\']').val(ns) } var timer; $('.quantity_cart [type="text"]').on("input", function() { window.clearTimeout(timer); timer = window.setTimeout(mathC.bind(this), 1200) }) }); |
MixPetrov,
вы пишите бред, переменная product_id с неба прилетит. Цитата:
|
Согласен с выше написанным.
В файле js $ (function () { function mathC(product_id, nmb){ var nmb = +($('input[name=\'' + product_id + '\']').val().dataset.nmb); // var ns = +this.value; //ns = ns || 0; //ns = Math.ceil(ns/nmb)*nmb; //this.value = ns var ns = +$('input[name=\'' + product_id + '\']').val(); ns = ns || 0; ns = Math.ceil(ns/nmb)*nmb; $('input[name=\'' + product_id + '\']').val(ns) } var timer; $('.quantity_cart [type="text"]').on("input", function() { window.clearTimeout(timer); timer = window.setTimeout(mathC, 1200) }) }); В файле php (firebug) <div class="quantity_cart"> <span class="minus" onclick="quantity(2, '-10', '20', '125')"><</span> <input name="2" oninput="mathC(2,10); isright(2,125,20); recalc(2);" size="2" value="20" maximum="125" quantity="125" minimum="10" data-nmb="10" type="text"> <span class="plus" onclick="quantity(2, '+10', '10', '125')">></span> </div> |
MixPetrov,
не будет работать |
Куда копать?
|
|
Спасибо
|
Часовой пояс GMT +3, время: 10:47. |