我正在檢查輸入字段中是否至少有一位數字。如果有我想更改默認圖像。使用isNumeric檢查輸入中的數字
我收到.isNumeric
函數的錯誤。我知道在文檔中顯示$.isNumeric
,但我不知道如何在hasNumber.isNumeric().length >= 1;
內添加該文件。
我打開一個不同的功能,如果它允許這個工作。
$('#register').keyup(function() {
var hasNumber = $("#password").val();
var hasNumberValid = hasNumber.isNumeric().length >= 1;
$('#upperCase').attr('src', hasNumberValid ? 'https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcQlyqJ14HYP1WclpK9RkJWo8jIDBkhTW0GS31AxRkozAEA72ULhY89LIzk' : 'icons/collection/delete.png');
});
#password-check {
margin: 30px auto;
}
.password-check-field {
color: black;
}
.password-check-field img {
margin-right: 15px;
height: 15px;
width: 15px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<form action="" method="POST" id="register">
<div class="field">
<label for="firstname">First Name</label>
<input type="text" name="firstname" required>
</div>
<div class="field">
<label for="password">Choose a password</label>
<input type="password" name="password" id="password" required>
</div>
<div class="password-check-field">
<img id="upperCase" src="icons/collection/delete.png" alt="Success">Your password has at a number in it
</div>
</form>
嘗試'$ .isNumeric(hasNumber)'' – j08691
變種ISNUMERIC = $ .isNumeric(value_to_check);' –
https://api.jquery.com/jQuery.isNumeric/。嘗試'$ .isNumeric(hasNumber)' –