我已经写了相同的JavaScript两次,两个文本框,但它同时运行一个文本框脚本我需要编写一次,调用相同的多个文本框JavaScript验证的onblur
function checkalphabets() {
var pattern = /^[a-zA-Z\s]+$/;
if (!pattern.test(myTextBox.value)) {
modal({
type: 'warning',
title: 'Warning',
text: 'Only Alphabets allowed!',
center: false,
callback: function(){ $("#myTextBox").focus();}
});
exit;
return false;
}
return true;
}
function checkalphabets1() {
var pattern = /^[a-zA-Z\s]+$/;
if (!pattern.test(TextBox1.value)) {
modal({
type: 'warning',
title: 'Warning',
text: 'Only Alphabets allowed!',
center: false,
callback: function(){ $("#TextBox1").focus();}
});
exit;
return false;
}
return true;
}
$('.modal-btn').click(function() {
$('#modal-window').hide();
});
这里是fiddle
您应该在尝试提取它们的值之前定义myTextBox和TestBox1。 – 2015-04-02 07:39:32