次のようなJQuery検証ファイルがあります。
$('#TextBoxRisultati2b').on('blur', function () {
var $this = $('#TextBoxRisultati2b');
if ($this.val() == '' || $this.val() === undefined) $this.val('0');
});
$('#TextBoxRisultati6b').on('blur', function () {
var $this = $('#TextBoxRisultati6b');
if ($this.val() == '' || $this.val() === undefined) $this.val('0');
});
$('#TextBoxRisultati10b').on('blur', function () {
var $this = $('#TextBoxRisultati10b');
if ($this.val() == '' || $this.val() === undefined) $this.val('0');
});
$('#TextBoxRisultati14b').on('blur', function () {
var $this = $('#TextBoxRisultati14b');
if ($this.val() == '' || $this.val() === undefined) $this.val('0');
});
$('#TextBoxRisultati18b').on('blur', function () {
var $this = $('#TextBoxRisultati18b');
if ($this.val() == '' || $this.val() === undefined) $this.val('0');
});
$('#TextBoxRisultati22b').on('blur', function () {
var $this = $('#TextBoxRisultati22b');
if ($this.val() == '' || $this.val() === undefined) $this.val('0');
});
$('#TextBoxRisultati4').on('blur', function () {
var $this = $('#TextBoxRisultati4');
if ($this.val() == '' || $this.val() === undefined) $this.val('0');
});
$('#TextBoxRisultati8').on('blur', function () {
var $this = $('#TextBoxRisultati8');
if ($this.val() == '' || $this.val() === undefined) $this.val('0');
});
$('#TextBoxRisultati12').on('blur', function () {
var $this = $('#TextBoxRisultati12');
if ($this.val() == '' || $this.val() === undefined) $this.val('0');
});
$('#TextBoxRisultati16').on('blur', function () {
var $this = $('#TextBoxRisultati16');
if ($this.val() == '' || $this.val() === undefined) $this.val('0');
});
$('#TextBoxRisultati20').on('blur', function () {
var $this = $('#TextBoxRisultati20');
if ($this.val() == '' || $this.val() === undefined) $this.val('0');
});
$('#TextBoxRisultati24').on('blur', function () {
var $this = $('#TextBoxRisultati24');
if ($this.val() == '' || $this.val() === undefined) $this.val('0');
});
$('#TextBoxObiettivi3').on('blur', function () {
var $this = $('#TextBoxObiettivi3');
if ($this.val() == '' || $this.val() === undefined) $this.val('0');
});
$('#TextBoxObiettivi6').on('blur', function () {
var $this = $('#TextBoxObiettivi6');
if ($this.val() == '' || $this.val() === undefined) $this.val('0');
});
$('#TextBoxObiettivi9').on('blur', function () {
var $this = $('#TextBoxObiettivi9');
if ($this.val() == '' || $this.val() === undefined) $this.val('0');
});
$('#TextBoxObiettivi12').on('blur', function () {
var $this = $('#TextBoxObiettivi12');
if ($this.val() == '' || $this.val() === undefined) $this.val('0');
});
$('#TextBoxObiettivi15').on('blur', function () {
var $this = $('#TextBoxObiettivi15');
if ($this.val() == '' || $this.val() === undefined) $this.val('0');
});
$('#TextBoxObiettivi18').on('blur', function () {
var $this = $('#TextBoxObiettivi18');
if ($this.val() == '' || $this.val() === undefined) $this.val('0');
});
選択はすべて同じです。検証ファイル全体は非常に冗長です。このコードを最適化する方法はありますか?