次のコードを追加すると、ページの書式設定が正しくありません。
$('#Inventory_accountNumber').blur(function(){
var accounts = $(this).val();
accounts = accounts.replace(/-/g,'');
var accountNum = [];
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 == 31) {
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 += accountNum[i].substring(24,28) + '-';
newstr += accountNum[i].substring(28,31);
accountNum[i] = newstr;
}
}
accountNum.join(',');
$(this).val(accountNum);
});
jsfiddle は、使用中のこのコードを示しています: http://jsfiddle.net/Lwv4U/14/
ご覧のとおり、jsfiddle では機能しますが、ライブ フォーマットの問題が存在します。以下のスクリーンショットは、コードが追加されたページと追加されていないページを示しています。このコードは、2 つのコード ベース間のコードの唯一の変更点です。問題があれば、Yii がフレームワークとして使用されています。
前
後