Nicks Lösung hat O (n) Komplexität. Hier ist ein optimiertes Beispiel.
Funktion isUnique
bestimmt das erforderliche Ergebnis.
<script src="jquery.js" />
<script>
function isUnique(tableSelector) {
// Collect all values in an array
var values = [] ;
$(tableSelector + ' td:first-child input[type="text"]').each(function(idx,val){ values.push($(val).val()); });
// Sort it
values.sort() ;
// Check whether there are two equal values next to each other
for(var k = 1; k < values.length; ++k) {
if(values[k] == values[k-1]) return false ;
}
return true ;
}
// Test it
$(document).ready(function(){
alert(isUnique(".myTable")) ;
});
</script>
<table class="myTable">
<tr><td><input type="text" value="1" /></td></tr>
<tr><td><input type="text" value="2" /></td></tr>
</table>
Nein, Ihr Englisch ist nur meh. – hobodave
@hobodave: Danke. Ich weiß, aber manchmal was kann ich tun? Ich versuche. :) – loviji
Ich kritisiere nicht, nur zu erklären. – hobodave