if($ .isNumeric(dataArray [i] .value)){}

时间:2015-12-05 01:25:20

标签: javascript jquery html arrays validation

<form id='myform'>
  <input name='letra'value='a'/>
  <input name='letra' value='b'/>
  <input name='number1' value='1'/>
  <input name='letra' value='d'/>
  <input name='number2' value=''/>
  <input name='letra' value='f'/>
</form>

我的jquery是

var dataArray = $("#myform").serializeArray(),
len = dataArray.length;


for (i=0; i<len; i++) {
    if(dataArray[i].name == 'number1' || dataArray[i].name == 'number2' ) {
        if($.isNumeric(dataArray[i].value)){
            alert('campo '+dataArray[i].name +' is number');
        }else
            alert('campo '+dataArray[i].name +' not number');      
    }else
        alert('campo '+dataArray[i].name +' si tiene');
    }

控制台告诉我:

未捕获的TypeError:$ .isNumeric不是函数

ani帮忙吗?是为了优化我的源码c:,或者我不知道如何使用$ .isNumeric?

1 个答案:

答案 0 :(得分:0)

还有其他一些代码会导致问题吗?是冲突吗?试试jQuery.isNumeric?

您发布的代码对我来说很好

&#13;
&#13;
var dataArray = $("#myform").serializeArray(),
len = dataArray.length;


for (i=0; i<len; i++) {
    if(dataArray[i].name == 'number1' || dataArray[i].name == 'number2' ) {
        if($.isNumeric(dataArray[i].value)){
            alert('campo '+dataArray[i].name +' is number');
        }else
            alert('campo '+dataArray[i].name +' not number');      
    }else
        alert('campo '+dataArray[i].name +' si tiene');
    }
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<form id='myform'>
  <input name='letra'value='a'/>
  <input name='letra' value='b'/>
  <input name='number1' value='1'/>
  <input name='letra' value='d'/>
  <input name='number2' value=''/>
  <input name='letra' value='f'/>
</form>
&#13;
&#13;
&#13;