0

我已经编写了 onKeyPress 事件,它在用户输入一些文本时验证文本,然后从某个字段中跳出标签应该验证文本,如果没有输入任何内容或输入不正确的值,应该给出错误通知用户并且焦点应该回到该字段并且用户必须除了字段的帮助按钮外,不允许进入下一个字段。

<jade:input type="text" name="dtxtDesigCd" 
    value="" size="10" maxlength="8" 
    classname="input" disabledclass="disabled-input" style="color: black"  
    datasource="dsDesigHourDetail:desigCode"
    onkeypress= "checkDesignation(this, event);">
</jade:input> 

我还有一个自定义 JSP 标记“PickList”,它基本上是一个按钮,它显示一个模式窗口,从数据库中获取相关字段的帮助,从帮助窗口中选择后,从数据库中选择的记录显示到 JSP 中的文本字段中。

我们早期的供应商使用了修改后的 SOFIA 框架,现在我必须维护代码。早期代码的问题是必须双击此按钮才能获得帮助,因为它使用 onblur 而不是 onkeypress,并且需要多次尝试,因为它不断给出错误。

早期的 onblur 代码是

    onblur="setValue('DESIGNATION');" onkeyup="capitalize(this);"

现在已替换为

    onkeypress= "checkDesignation(this, event);">

JSP中帮助按钮/PickList的代码如下:

<rap:pickfromlist name="picklistDesignation" datasource="dsDesigHourDetail" 
    pflheading="Designation Details" focusfield="dtxtDesigCd"
    pflcolumnsdesc="Designation Code, Description" 
    fieldlist="distinct emp_desig_cd, emp_desig_desc " 
    lookuptable="pmm_designation" orderby="emp_desig_cd"
    targetproperty="desigCode, designation" 
    whereclause=" executive_post='N' and crew_flg = 'N'" /> 

在此字段中,指定的描述被捕获为从选择列表中选择或在通过 setValue 方法提交表单后,该方法通过表单中的隐藏变量操作将传递的值发送到服务器并提交表单。

<jade:input type="text" name="dlblDesigDesc" value="" size="50" 
    classname="labeltext" style="color: black" 
    datasource="dsDesigHourDetail:designation" enabled="False">
</jade:input>

checkDesignation(obj, evt) 定义为

function checkDesignation(obj, evt) {
    var evt = (evt) ? evt : (window.event) ? event : null;
    if (evt) {
        var len = TrimString(obj.value).length;
        alert("Designation : " + obj.value);
        if (evt.keyCode == 9 && len >= 0) {
            if (len == 0) {
                setErrMessage('Designation must be entered and not blank');
                document.forms[0].htmlPageTopContainer_pageForm_detailDesigHourForm_dtxtDesigCd.focus();
                document.forms[0].htmlPageTopContainer_pageForm_detailDesigHourForm_dtxtDesigCd.value = '';
                setValue('DESIGNATION');
                return false;
            } else {
                capitalize(obj);
                setValue('DESIGNATION');
                return true;
            }
        }
    }
} 
4

1 回答 1

1

检查这个

    $("#textbox").bind("onKeyPress ", function (e) {
                if (e.altKey || e.ctrlKey || e.shiftKey){
                    return true;
    }
    else{
    // you have this text box inner text in this.val() and can be checked with 
           your validate function.
    }
            });
于 2013-04-05T13:21:06.437 回答