如何只允许在jqGrid单元格编辑中使用数字
How to allow numbers only in jqGrid cell editing?
当网格可编辑时,键入时只接受数字如何操作?
JSP网格加载代码:
<s:url id="mobbillid" action="newmul_mob_gridact" />
<sjg:grid caption="EMPLOYEE MOBILEBILL DETAILS"
gridModel="mobbill_gridModel"
height="200"
href="%{mobbillid}"
id="gridtab"
cellEdit="true"
cellurl="%{mobbillid}"
rownumbers="true"
viewrecords="true"
pager="true"
pagerPosition="center"
navigator="true"
navigatorSearch="true"
navigatorSearchOptions="{multipleSearch:true}"
navigatorDelete="false"
navigatorEdit="false"
loadonce="true"
rowNum="10000"
multiselect="true"
reloadTopics="reloadSearchedClaims"
footerrow="false"
userDataOnFooter="true"
onSelectRowTopics="rowselect"
>
<sjg:gridColumn name="newsin_mob_faname" index="newsin_mob_faname" title="FAcode" width="100" />
<sjg:gridColumn name="newsin_mob_name" index="newsin_mob_name" title="FANAME" width="100" />
<sjg:gridColumn name="newsin_mob_no" index="newsin_mob_no" title="MOBNO" width="100" />
<sjg:gridColumn name="newsin_mob_billno" index="newsin_mob_billno" title="BILLNO" width="40" editoptions="true" editable="true" />
<sjg:gridColumn name="newsin_mob_billamt" index="newsin_mob_billamt" title="BILLAMT" width="90" editable="true" />
<sjg:gridColumn name="newsin_mob_othchrg" index="newsin_mob_othchrg" title="OTHCHRG" width="95" editable="true" />
<sjg:gridColumn name="newsin_mob_psts" index="newsin_mob_psts" title="refid" width="70" align="right" hidden="true"/>
<sjg:gridColumn name="newsin_mob_rmrk" index="newsin_mob_rmrk" title="REMARK" width="75" align="right" editable="true"/>
<sjg:gridColumn name="newsin_mob_opnbal" index="newsin_mob_opnbal" title="OPNBAL" width="75" align="right" hidden="true"/>
</sjg:grid>
您可以使用一些jquery来处理此问题,请查看以下内容:http://jsfiddle.net/yrshaikh/44pc78pj/
你可以让你的可编辑文本框有一个名为.allownumericwithdecimal
的类,并使用下面的代码
$(".allownumericwithdecimal").on("keypress keyup blur",function (event) {
$(this).val($(this).val().replace(/[^0-9'.]/g,''));
if ((event.which != 46 || $(this).val().indexOf('.') != -1) && (event.which < 48 || event.which > 57)) {
event.preventDefault();
}
});
如果你的网格文本框是动态添加的,你需要做一些类似的事情
$(document).on('keypress keyup blur', '.allownumericwithdecimal', function () {
$(this).val($(this).val().replace(/[^0-9'.]/g, ''));
if ((event.which != 46 || $(this).val().indexOf('.') != -1) && (event.which < 48 || event.which > 57)) {
event.preventDefault();
}
});
Jsp代码:
<s:url id="mobbillid" action="newmul_mob_gridact" />
<sjg:grid caption="EMPLOYEE MOBILEBILL DETAILS"
gridModel="mobbill_gridModel"
height="200"
href="%{mobbillid}"
id="gridtab"
cellEdit="true"
cellurl="%{mobbillid}"
rownumbers="true"
viewrecords="true"
pager="true"
pagerPosition="center"
navigator="true"
navigatorSearch="true"
navigatorSearchOptions="{multipleSearch:true}"
navigatorDelete="false"
navigatorEdit="false"
loadonce="true"
rowNum="10000"
multiselect="true"
reloadTopics="reloadSearchedClaims"
footerrow="false"
userDataOnFooter="true"
onSelectRowTopics="rowselect"
>
<sjg:gridColumn name="newsin_mob_faname" index="newsin_mob_faname" title="FAcode" width="100" />
<sjg:gridColumn name="newsin_mob_name" index="newsin_mob_name" title="FANAME" width="100" />
<sjg:gridColumn name="newsin_mob_no" index="newsin_mob_no" title="MOBNO" width="100" />
<sjg:gridColumn name="newsin_mob_billno" index="newsin_mob_billno" title="BILLNO" width="40" editoptions="true" editable="true" editrules="{number:true}"/>
<sjg:gridColumn name="newsin_mob_billamt" index="newsin_mob_billamt" title="BILLAMT" width="90" editable="true" edittype="text" editrules="{number:true}"/>
<sjg:gridColumn name="newsin_mob_othchrg" index="newsin_mob_othchrg" title="OTHCHRG" width="95" editable="true" editrules="{number:true}"/>
<sjg:gridColumn name="newsin_mob_psts" index="newsin_mob_psts" title="refid" width="70" align="right" hidden="true"/>
<sjg:gridColumn name="newsin_mob_rmrk" index="newsin_mob_rmrk" title="REMARK" width="75" align="right" editable="true" />
<sjg:gridColumn name="newsin_mob_opnbal" index="newsin_mob_opnbal" title="OPNBAL" width="75" align="right" hidden="true"/>
</sjg:grid>
使用editrules="{number:true}"
当焦点离开时,如果它是字母表,它会触发向您显示错误消息
相关文章:
- CKEditor Widget-阻止编辑可编辑元素本身
- 如何在angularJS中编辑时,如果DB中的值为true,则设置复选框,如果值为false,则取消选中复选框
- 通过单击表单中的按钮,在代码生成中使用javascript生成字母数字代码
- 测试索引值是否等于某个数字的倍数
- 高亮显示时编辑文本大小和颜色
- 剑道UI内联编辑:如何在点击其他按钮时隐藏按钮
- 将数字转换为一定数量的硬币
- 将事件聚焦/模糊在可编辑内容的元素上
- 键入最后一位数字后自动提交
- 如何在javascript中迭代数字列表
- Javascript逻辑运算符和字符串/数字
- 如何在javascript中获得与特定数字相等的随机数
- 如果元素's的ID以数字开头
- 计算content中的数字总和使用Jquery可编辑文本
- 如何只允许在jqGrid单元格编辑中使用数字
- 如何编辑这个JS代码,以便在散列文本中添加字符,而不仅仅是数字
- 可编辑的数字类型未定义
- 编辑:为什么typeof(0)返回布尔值而不是数字?
- CK编辑项目符号和数字格式
- 找到一个数字的所有排列,没有重复(为清晰起见编辑)