Показать сообщение отдельно
  #16 (permalink)  
Старый 31.10.2017, 12:55
Профессор
Отправить личное сообщение для the_little Посмотреть профиль Найти все сообщения от the_little
 
Регистрация: 25.09.2017
Сообщений: 186

Сообщение от Nexus Посмотреть сообщение
the_little, вы все поправили?

Сейчас все работает как нужно.
это на сайте работает нормально)) а у меня нет...

У меня если я очищаю поле с площадью - в поле количество упаковок остается 0.
А нужно чтобы оставалась 1.

<!DOCTYPE html>
<html lang=ru> 

<head> 
<meta charset="utf-8">  
<title>Калькулятор</title>  

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>

<body>
<style type="text/css">
	#calc .description { margin-bottom: 30px; }
	#calc .old-price { text-decoration: line-through; }
	#calc .new-price { color: darkred; }
	#calc .price { margin-bottom: 30px; }
	#calc label { margin-bottom: 20px; }
	input::-webkit-outer-spin-button,
	input::-webkit-inner-spin-button {
    /* display: none; <- Crashes Chrome on hover */
    -webkit-appearance: none;
    margin: 0; /* <-- Apparently some margin are still there even though it's hidden */
}
</style> 



<div id="calc">
	<div class="description">
		<h4>Описание товара</h4>
		...<br>
		Кол-во м2 в уп.: <span id="count">1.9218</span> м2
	</div>
	<div class="price">
		<span>Цена:</span>
		<span class="old-price">1590</span>
		<span>руб.</span>
		<span class="new-price">1462</span>
		<span>руб.</span>
	</div>
	<div>
		<label for="u-m">Введите требуюмую площадь: </label>
                <input type="number" step="any" name="user_amount" id="u-m" min="0">
		<span>( <span class="calc-amount">?</span> м) = <span class="calc-price">?</span> руб.</span>
		<br><br>
		<label for="b-m">Количество упаковок: </label>
		<input type="number" step="1" name="bag_amount" id="b-m" min="1" value="1">
	</div>
</div>

<script type="text/javascript">

$(document).ready(function() {
	$("#b-m,#u-m").keyup(function(){		
		var $t=$(this),						
			bool=$t.attr('id')=='u-m',		
			um=$("#u-m").val(),
			count=$("#count").html(),
			amount=bool?					
				Math.ceil(um / count):      
				$("#b-m").val(),
			price=$(".new-price").html();
			
		if(bool)							
			$("#b-m").val(amount);

		$(".calc-amount").text(amount * count);
		$(".calc-price").text((amount * count * price).toFixed(2));

	});
});
</script>
</body>
</html>

Последний раз редактировалось the_little, 31.10.2017 в 13:12.
Ответить с цитированием