我写了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的文本字段后,从帮助窗口选择。
修改后的索非亚框架是由我们的早期供应商使用的,现在我必须维护代码。早期代码的问题是,必须双击此按钮才能获得帮助,因为它使用onblur而不是onkeypress,并且需要多次尝试,因为它不断出现错误。
onblur的早期代码是
onblur="setValue('DESIGNATION');" onkeyup="capitalize(this);",现在已被替换为
onkeypress= "checkDesignation(this, event);">JSP中help按钮/ 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;
}
}
}
} 发布于 2013-04-05 21:21:06
看看这个
$("#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.
}
});https://stackoverflow.com/questions/15834834
复制相似问题