数字以外の文字に対してさまざまな入力フィールドを検証する必要があります。私はまた、ブートストラップ警告を使用しています。だから私は以下のコードを持っています。初めてエラーが発生したときに正常に動作します。あなたはBSアラートを取得します。しかし、後続の入力にエラーが発生した場合、コードは機能しません。つまり、アラートは表示されません.2つのvarsの数量と数量をチェックして、2回目のコードの内容をチェックしています。非数字の文字。しかし何らかの理由でNaNはそれを見ません。私は間違って何をしていますか?isNaNはなぜ2度目に呼び出されないのですか?
$(".product_table").on('change', '.edit_quantity',function(){
var qty = $(this).find('input').val();
var quantity = $(this).parents(':eq(1)').find('input').filter(".edit_quantity").val();
console.log('l 117', qty);
console.log('l 118', quantity);
if (isNaN(quantity||qty))
{
$("#char_error").show();
}
else
{
//more code goes here//
}
}
HTML:
<div id="char_error" class="alert alert-danger">
<strong>Error</strong> You have entered an illegal character in the quantity box, please enter a number.
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
さらに、私も理想的ではない<div id="char_error">
これを非表示にすることで、私のJSファイルを起動するには消え、ビューに内容が点滅しています。
を必要とする代わりに、それを
と同じものです。 – SLaks
[問題を示す実例を提供する](http://stackoverflow.com/help/mcve)できますか? – whipdancer