我有文本框列表,其中包含百分比值,如2.5%等。有一个验证可以检查用户是否输入了任何特殊字符。如果是这样,警告框应弹出适当的警报消息。但是,无论何时输入任何无效数据,警报框都不会关闭。从任务管理器。我必须关闭IE。任何帮助将不胜感激。
JSP代码 -
<html:text property="manualValPctNum" name="manualValueInputPO" styleId="manualValPctNum" size="25" indexed="true" maxlength="25" onblur="javascript:formatValues('moduleForm', '${row.index}')" onfocus="javascript:removeValueFormat('moduleForm', '${row.index}')"/>
JavaScript代码 -
function formatValues(form, rowIndex){
var beginElem = "manualValueInputPO[";
var endElement = "]";
var attributeName =beginElem+ rowIndex+endElement;
formatPercentAmount(form,attributeName);
value = "";
}
function formatPercentAmount(form, attributeName){
var manualValueAmt = document.getElementsByName(attributeName+".manualValueAmt")[0];
var manualValPctNum = document.getElementsByName(attributeName+".manualValPctNum")[0];
var decimalForTabOut = document.getElementsByName(attributeName+".decimalForTabOut")[0];
if(manualValPctNum.value != undefined && manualValPctNum.valu`enter code here`e != ''){
if(isNaN(manualValPctNum.value)){
alert("Enter numeric value only without entering any '$', comma, '( )', '%', or alphabets. Use '-' when entering a negative value.");
value = "true";
manualValPctNum.focus();
manualValPctNumFlag = true;
modifiedString = "";
replacedChar = "";
}else{
var amt = manualValPctNum.value;
amt = amt.toString();
decimalForTabOut.value = amt.indexOf('.');
var indexPos = amt.indexOf('.');
if(indexPos == -1){
modifiedString = amt.concat("00");
nonDecimalPoint = true;
}else{
var pctNumBeforeDecimal = amt.substring(0,indexPos);
var pctNumAfterDecimal = amt.substring(indexPos + 1,amt.length);
var modifiedIndexPos = indexPos + 2;
var pctNum = pctNumBeforeDecimal.concat(pctNumAfterDecimal);
for(var i = 0; i<pctNum.length; i++){
if(i == modifiedIndexPos){
replacedChar = pctNum[i];
modifiedString = modifiedString.concat('.');
modifiedString = modifiedString.concat(replacedChar);
}else{
if(modifiedString == undefined || modifiedString == ""){
modifiedString = pctNum[i];
}else{
modifiedString = modifiedString.concat(pctNum[i])
}
}
}
}
manualValueAmt.value = modifiedString+"%";
manualValPctNum.value = modifiedString+"%";
modifiedString = "";
replacedChar = "";
manualValPctNumFlag = false;
}
}
}
答案 0 :(得分:0)
请使用onClick事件更改onFocus事件, 使用onFocus,只要您点击浏览器上的可用空间,它就会调用该功能