87,993
社区成员
发帖
与我相关
我的任务
分享Array.prototype.forEach = function(action) {
for (var i=0; i<this.length; i++)
action(this[i], i, this);
};
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); };
// 默认所有表单内的元素都是 input ,且 type=text|password
function checkSame(frm) {
var map = {};
with ([]) {
forEach.call(frm.elements, function(e) { if (/^abc\d+$/.test(e.name)) push(e); });
forEach(function(e) { e.value = e.value.trim(); });
try {
forEach(function(input) {
if (input.value!="") return;
input.focus();
throw new Error(-1, input.name + "不能为空值!");
});
forEach(function(input, i) {
if (map[input.value]) {
input.focus();
throw new Error(-1, map[input.value].name + " 与 " + input.name + " 重复!");
}
map[input.value] = input;
});
} catch(e) {
alert(e.message);
return false;
}
}
window.open ("http://www.163.com");
}