ユーザー入力に数字ではなく文字が含まれているかどうかを確認するjquery関数を作成しています。基本的な機能を動作させようとしているだけで、アラートボックスを使用してこれをテストしています。何が入力されたかに関係なく、テストはアラートを表示する必要があります。数字を入力すると機能しますが、他の文字を入力してもアラートは発生しません。ここで何が起こっているのかアイデアはありますか?
フォームはdivに含まれるフィールドセットに分割され、オーバーレイとしてポップアップ表示されます。この関数は、ユーザーがポップアップウィンドウを閉じようとするたびに呼び出されます。これが問題を引き起こすはずではありませんか?
テスト機能は次のとおりです。
function validateItem(item){
var fvalue = $(item).val();
alert(fvalue);
return false; }
これがサンプルのテーブルアイテムです
<tr>
<td class="td_thumbs">
<div>
<a class="fancybox" data-fancybox-group="vinyl-banners" href="img/products/vinyl-corporateblue.jpg"> <img src="img/products/thumbs/vinyl-corporateblue-thumb.png" alt="vinyl c-blue"/></a>
<label>Corporate Blue</label>
</div>
</td>
<td>6</td>
<td>
<input id="vinyl-blue" type="text" max="6" min="0" value="0"/>
</td>
</tr>
呼び出し元の関数、
//iterate through each table
$('table').each(function() {
$thisTable = $(this);
//iterate through each input
$(this).find('input').each(function() {
var $this = $(this), i_value = $this.attr('value'),
itemLabel = $this.closest('tr').find('label').html();
//if any items have a positive value
if (i_value > 0) {
//we want to grab the heading for these items
setHeading = true;
//validate item
if(validateItem($this)){//if quantities are valid
//build list of items of this type
$this.css({
'border':'1px solid #ddd',
'background-color' : '#efefef'
});
items += '<li>' + i_value + 'x ' + itemLabel + '</li>';
}
else{//invalid quantity
$this.css({
'border':'1px dashed #F00',
'background-color' : '#f7d2d4'
});
errorFlag = true;
//exit item and table loops
return false;
}//end validate
}//end value check
});//end input iteration