function forbitSpecialCharactor(input){
var value = input.value;
var spec = "\"";
var firstIndex = value.indexOf(spec);
var lastIndex = value.lastIndexOf(spec);
if(firstIndex == -1){
return true;
}else{
// 只有一个"\""时,直接删除该字符
if(firstIndex == lastIndex){
var after = "";
if(value.length - 1 > firstIndex){
after = value.substring(firstIndex + 1, value.length);
}
input.value=value.substring(0, firstIndex).concat(after);
}else{
//如果copy含多个"\""字符的字符串到控件中,把输入框设为空值
input.value="";
}
return false;
}
}
调用:
<html:text property="xx.xx" size="30" maxlength="150" οnkeyup="forbitSpecialCharactor(this)"/>
var value = input.value;
var spec = "\"";
var firstIndex = value.indexOf(spec);
var lastIndex = value.lastIndexOf(spec);
if(firstIndex == -1){
return true;
}else{
// 只有一个"\""时,直接删除该字符
if(firstIndex == lastIndex){
var after = "";
if(value.length - 1 > firstIndex){
after = value.substring(firstIndex + 1, value.length);
}
input.value=value.substring(0, firstIndex).concat(after);
}else{
//如果copy含多个"\""字符的字符串到控件中,把输入框设为空值
input.value="";
}
return false;
}
}
调用:
<html:text property="xx.xx" size="30" maxlength="150" οnkeyup="forbitSpecialCharactor(this)"/>