0

Всем отличного настроения!

Пытаюсь выполнить событие, если value у элемента input=text достигло необходимого значения:

$( function() {
    $( "#slider" ).slider({
        value:5000,
        min: 0,
        max: 300000,
        step: 5000,
        slide: function( event, ui ) {
            $( "#amount" ).val( ui.value );
        }
    });
    var strAmountValue = $('#amount').attr("value");
    if (strAmountValue === 300000) {
        alert("Добро пожаловать!");
    }
} );
.form .range.budget label {
    font-family: "Roboto";
    font-size: 18px;
    text-transform: uppercase;
}
.form .range.budget .ui-slider {
    height: 2px;
    border: 1px solid #111;
    background-color: #111;
}
.form .range.budget .ui-slider-handle {
    left: 2%;
    background: #ffd218;
    width: 20px;
    height: 20px;
    border-radius: 20px;
    position: absolute;
    top: -9px;
    border: 1px solid #222;
}
#amount.budget {
    color: #ef0832;
    border: none;
    font-weight: bold;
    font-family: "Roboto";

}
<link href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

<div class="form">
  <div class="form_group range budget">
      <p>
          <label for="amount">Бюджет:</label>
          <input type="text" id="amount" class="budget_value" readonly>
      </p>
      <div id="slider"></div>
  </div>
</div>

но событие не срабатывает, хотя я по идее в переменной получил через attr("value") значение элемента и задал условие. Подскажите что не так делаю?

2

1 ответ 1

0
slide: function( event, ui ) {
    if (ui.value == 30000) {
        alert('Привет!');
    }
    $( "#amount" ).val( ui.value );
}
1

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.