控制台中不存在任何错误,尽管该功能似乎没有像预期的那样添加破折号。此外,该代码会在网站上产生格式问题,这意味着存在问题。
代码:
$('#Inventory_accountNumber').blur(function(){
var accounts = $(this).val;
var accountsNum = [];
accountNum = accounts.split(",");
for(var i=0;i<accountNum.length;i++) {
var newstr = '';
if(accountNum[i].length == 24) {
newstr += accountNum[i].substring(0,4) + '-';
newstr += accountNum[i].substring(4,7) + '-';
newstr += accountNum[i].substring(7,10) + '-';
newstr += accountNum[i].substring(10,14) + '-';
newstr += accountNum[i].substring(14,20) + '-';
newstr += accountNum[i].substring(20,24) + '-';
newstr += '0000-000';
accountNum[i] = newstr;
}
else if(accountNum[i].length == 32) {
newstr += accountNum[i].substring(0,4) + '-'
; newstr += accountNum[i].substring(4,7) + '-';
newstr += accountNum[i].substring(7,10) + '-';
newstr += accountNum[i].substring(10,14) + '-';
newstr += accountNum[i].substring(14,20) + '-';
newstr += accountNum[i].substring(20,24) + '-';
newstr += '0000-000';
accountNum[i] = newstr;
}
}
accountNum.join(',');
$(this).val = accountNum;
});