javascript.html 549 B

12345678910111213141516171819
  1. <script type="text/javascript">
  2. $(function() {
  3. //给数组增加查找指定的元素索引方法
  4. Array.prototype.indexOf = function(val) {
  5. for (var i = 0; i < this.length; i++) {
  6. if (this[i] == val) return i;
  7. }
  8. return -1;
  9. };
  10. //给数组增加删除方法
  11. Array.prototype.remove = function(val) {
  12. var index = this.indexOf(val);
  13. if (index > -1) {
  14. this.splice(index, 1);
  15. }
  16. };
  17. });
  18. </script>