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> |
Есть кто знает помогите пожалуйста!!!
|
Ничего не понятно, поясните - когда меняем значение input (не обновляя) хранится самое первое набитое значение, в чем проблема?
|
когда меняем значения второго input у него в памяти остается своя первая значения (перво набитая)
|
побробуйте набивать другую значению (не обновляя страницу) во второй инпут он показоват будет свою первую значению в контексте ошибке
|
как избавиться от этого?
|
Сообщение не обновляется, а то штаны, штаны. ) Попробуйте так:
$('#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"? |
Зачем type="number"? - eto ne obezatelno
no cto to ne to text oshibke ne vixodit. Vixodit tolko pustoe popover |
Все выводит, попробуйте событие в триггере заменить.
|
$(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, время: 00:14. |