了解 PHP 的朋友都知道, PHP 里面有个很好用的函数叫“in_array”,它可以用来检查数组中是否存在某个值,本文介绍的是通过 prototype 向 javascript 数组添加一个类似的方法,简单但是实用。
<script type="text/javascript">
Array.prototype.inArray = function (value) {
// Returns true if the passed value is found in the
// array. Returns false if it is not.
var i;
for (i=0; i < this.length; i++) {
// Matches identical (===), not just similar (==).
if (this[i] === value) {
return true;
}
}
return false;
};
</script>
Array.prototype.inArray = function (value) {
// Returns true if the passed value is found in the
// array. Returns false if it is not.
var i;
for (i=0; i < this.length; i++) {
// Matches identical (===), not just similar (==).
if (this[i] === value) {
return true;
}
}
return false;
};
</script>
如何阻止表单重复提交、防
数学方法、逻辑判断实现、


2007/01/18 14:24 | by 















