for single digit numric value elements, couldnt find the duplicates in jQuery
To find the duplicates, this is my extended function.
jQuery.extend(jQuery.expr[":"],{
duplicateValues:function(element){
var return_val = false;
jQuery(element).each(function(){
if(jQuery(element+"[value='"+jQuery(this).val()+"']").length > 1){
return_val = true;
return false;
}
开发者_StackOverflow });
return return_val;
}
});
and this is called as
if(jQuery('.option_text:duplicateValues').length > 0){
alert("Duplicate in answer options");
return false;
}
This is working fine for all alpha numeric and strings. If only single numeric value is given in the text box, without any duplication, it is showing the alert for duplication.
it is working fine for the single characters too.
Thanks in advance
Are you sure? i tested it with this markup (http://jsfiddle.net/nicolapeluchetti/dg9BE/1/):
<input type='text' value='1' class='option_text'/>
<input type='text' value='2' class='option_text'/>
<input type='text' value='3' class='option_text'/>
an this markup (http://jsfiddle.net/nicolapeluchetti/dg9BE/2/)
<input type='text' value='1' class='option_text'/>
And it was correct
精彩评论