Javascript-форум (https://javascript.ru/forum/)
-   jQuery (https://javascript.ru/forum/jquery/)
-   -   Clear cache !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! (https://javascript.ru/forum/jquery/78968-clear-cache.html)

Ganisher 29.11.2019 10:35

Clear cache !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
Вложений: 1
Всем привет!
когда меняем значение input (не обновляя) хранится самое первое набитое значение.
Вложение 4274
(выходить "16" а не "77")


<!DOCTYPE html>
<html>
	<head>
		<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<style>

.errorstyle
			{
			    border: 1px solid #ff0000;
			    background: #fff3f3;
			}
			.popover
			{
			    box-shadow: 5px 0px 40px rgba(0,0,0, .2);
			    max-width: 500px !important;
			    max-height: 200px !important;
			    overflow-y: auto;
			    overflow-x: hidden;
			    border: 1px solid #ff0000;
			    background: #fff3f3;
			}

</style>
		<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
		<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
		<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
		<script>

$(function(){
		    $('.container').on('focusout', '#second', function () {
		        let first = $('#first').val().trim();
		        let second = $('#second').val().trim();

		        if (second)
		            if (+first <= +second) {
		                
		                let errortext = '<p>The value of first (' + first +') input must be greater than the value of secondone (' + second	 + ')</p>';
		                let poperror = {
		                    content: errortext,
		                    html: true,
		                    trigger: 'focus',
		                    placement: 'bottom'
		                };
		                $('#second').popover(poperror).popover('enable');
		                $('#second').addClass("errorstyle");
		            } else {
		                $('#second').popover('disable');
		                $('#second').removeClass("errorstyle");
		            }
		    });
		});

</script>
	</head>
	<body>
		<div class="container">
		  <form>
		    <div class="form-group">
		      <label for="first">First:</label>
		      <input type="number" class="form-control" id="first" name="firstone">
		    </div>
		    <div class="form-group">
		      <label for="second">Second:</label>
		      <input type="number" class="form-control" id="second" name="secondone">
		    </div>
		  </form>
		</div>
	</body>
</html>

Ganisher 29.11.2019 10:38

Есть кто знает помогите пожалуйста!!!

laimas 29.11.2019 11:23

Ничего не понятно, поясните - когда меняем значение input (не обновляя) хранится самое первое набитое значение, в чем проблема?

Ganisher 29.11.2019 11:49

когда меняем значения второго input у него в памяти остается своя первая значения (перво набитая)

Ganisher 29.11.2019 11:53

побробуйте набивать другую значению (не обновляя страницу) во второй инпут он показоват будет свою первую значению в контексте ошибке

Ganisher 29.11.2019 11:56

как избавиться от этого?

laimas 29.11.2019 16:48

Сообщение не обновляется, а то штаны, штаны. ) Попробуйте так:

$('#second').popover({
         content: '<p></p>',
         html: true,
         trigger: 'blur',
         placement: 'bottom'
}).on('shown.bs.popover', function () { 
    var first = +this.form.firstone.value || 0,
        second = +this.value || 0;
    if(first && second && first <= second) { 
        $('div.popover-body p').text('The value of first (' + first +') input must be greater than the value of secondone (' + second + ')');
        $(this).addClass("errorstyle")
    } else {
        $('div.popover').remove();
        $(this).removeClass("errorstyle")
    }
});


Зачем type="number"?

Ganisher 02.12.2019 10:01

Зачем type="number"? - eto ne obezatelno

no cto to ne to
text oshibke ne vixodit. Vixodit tolko pustoe popover

laimas 02.12.2019 10:03

Все выводит, попробуйте событие в триггере заменить.

Ganisher 02.12.2019 12:31

$(function(){
			    $('.container').on('focusout', '#second', function () {
			        let first = +($('#first').val()) || 0,
			        	second = +($('#second').val()) || 0;

			        if (second)
			            if (first <= second) {
			                
			                //let errortext = '<p>The value of first (' + first +') input must be greater than the value of secondone (' + second + ')</p>';
			                let poperror = {
			                    content: '',
			                    html: true,
			                    trigger: 'hover focus',
			                    placement: 'bottom'
			                };
			                $('#second').popover(poperror).popover('enable');
			                $('#second').popover(poperror).text('<p>The value of first (' + first + ') input must be greater than the value of secondone (' + second + ')</p>');
			                $('#second').addClass("errorstyle");
			            } else {
			                $('#second').popover('disable');
			                $('#second').removeClass("errorstyle");
			            }
			    });
			});


Часовой пояс GMT +3, время: 05:30.