0

我有一个包含百分比值的文本框列表,例如 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;
        }
    }
}
4

1 回答 1

0

请用onClick事件更改onFocus事件,用onFocus,只要你点击浏览器上的空闲空间,它就会调用该函数

于 2017-06-05T09:22:09.500 回答