【发布时间】:2016-03-13 04:19:35
【问题描述】:
如何在 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);
}
【问题讨论】:
-
你的意思是这样Fiddle?让我知道,如果这是正确的,我会发布一个完整的答案来解释解决方案
-
是的,和 Fiddle 一样..@IanA
标签: javascript jquery css asp.net jquery-ui