开发者

JQuerys inArray Confusion

I trying to create a validation method to ensure that the users input value has not been previously entered as to avoid any duplicate names. I have seen the inArray method and thought that the following code would tell me if it had found the value in an array?

if(jQuery.inArray(newName, nameArray) >= 0)
{
    alert("found");
}
else  //if -1
{
    alert("not found");
    classnameArrays.push(newClassName);
}

Would anyone be able to see what is wrong with the code. All i am trying to achieve is to have the name inserted into the array if their is no other name of the same开发者_高级运维 value already present.

Thanks for any feedback.


That code is correct.

Could it be because you're checking to see if newName is in nameArray, but pushing newClassName into classnameArrays?

If you're still having trouble, install Firebug and use its debugger and interactive console to inspect the values you're dealing with. That usually helps me figure out this kind of problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜