如何在7个字母/字母表/数字和新行中的新字母后的键向上插入分隔符-Jquery
How to insert delimitter on key up after 7 letters/alphabet/numbers and new letters in new line- Jquery
如何在keyup事件中在7个字母后放置逗号,下面是我的代码,我可以在7个字符后获得逗号,但当它转到下一行时,它无法正常工作。
<asp:TextBox ID ="txtbillno" runat="server" onkeyup="InsertComma();" TextMode="MultiLine"></asp:TextBox>
function InsertComma() {
var txtObj = document.getElementById('<%=txtbillno.ClientID %>');
var txtVal = replaceAll(txtObj.value, ',', '');
if (txtObj.value != "") {
var newVal = "";
for (var i = 0; i < txtVal.length; i++) {
newVal = newVal + txtVal.substring(i, i + 1);
if ((i + 1) % 7 == 0 && i != 0) {
newVal = newVal + "," + "'n";
}
}
txtObj.value = newVal;
}
}
function replaceAll(txt, replace, with_this) {
return txt.replace(new RegExp(replace, 'g'), with_this);
}
在InsertComma
函数中,您正确地删除了逗号:
var txtVal = replaceAll(txtObj.value, ',', '');
但是txtVal
仍然包含新行字符(''n),所以我也添加了一行来删除这些字符:
txtVal = replaceAll(txtVal, ''n', '');
完整的InsertComma
方法是:
function InsertComma() {
var txtObj = document.getElementById('txtbillno');
// Remove commas
var txtVal = replaceAll(txtObj.value, ',', '');
// Remove new line characters
txtVal = replaceAll(txtVal, ''n', '');
if (txtObj.value != "") {
var newVal = "";
// Append commas
for (var i = 0; i < txtVal.length; i++) {
newVal = newVal + txtVal.substring(i, i + 1);
if ((i + 1) % 7 == 0 && i != 0) {
newVal = newVal + "," + "'n";
}
}
txtObj.value = newVal;
}
}
在这里可以找到一个工作示例
相关文章:
- 输入类型数字,只接受数字,不接受字母jQuery
- 用新的jQuery和jQuery ui替代.tabs(“添加”、链接、标题)
- 2秒后删除新的jQuery预处理节点
- 在新类 jQuery 上启用可拖动
- 如何修复javascript在较新的jquery库上运行,但在较旧版本的jquery库上运行
- 为什么 $(':radio').change() 在新的 jQuery 中停止工作
- css+jQuery样式.css切换器,用于新的jQuery版本
- 如何在7个字母/字母表/数字和新行中的新字母后的键向上插入分隔符-Jquery
- 创建新的jQuery全局对象
- 将CSS设置添加到新的JQuery插件中
- 非常新的JQuery初学者-放大弹出窗口
- 动画高度:自动与较新的jQuery
- 循环遍历集合中的jQuery对象,而不为每次迭代初始化一个新的jQuery对象
- 选择具有匹配文本关键字的元素,忽略大写字母(jQuery)
- 在新的JQuery对象内部迭代
- (新的jquery)为什么我的chrome扩展工作在任何东西,但reddit
- 在img加载打开新标签Jquery不点击
- 替换span与新的数据,但新的jquery调用不工作
- 在警告窗口新行jQuery jqXHR responseText
- 动态添加一个新的jQuery滑块会导致旧的滑块不起作用