2

次のコードがあります。

         $('#modal .update-title')
            .change(function () {
                var title = $('option:selected', this).prop('title');
                $(this).prop('title', title);

                // For the question screen, after the initial set up 
                // changes move the title to the title input field.
                if ($(this).data('propagate-title') === 'yes') {
                    var m = this.id.match(/^modal_TempRowKey_(\d+)$/);
                    if (m) {
                        $("#modal_Title_" + m[1]).val(title);
                    }
                }
            });

jslint を実行すると、次のエラーが表示されます。

   Combine this with the previous 'var' statement.
   var m = this.id.match(/^modal_TempRowKey_(\d+)$/);

jslint が間違っていますか、それとも私が間違っていますか?

4

1 に答える 1

5

if 条件を使用しても、新しいスコープは作成されません。したがって、変数 m は、条件が真の場合にのみ存在します。だからここにあなたができることがあります

$('#modal .update-title').change(function () {
    var title = $('option:selected', this).prop('title'),
    m = null; // or just m;
    $(this).prop('title', title);

    // For the question screen, after the initial set up 
    // changes move the title to the title input field.
    if ($(this).data('propagate-title') === 'yes') {
        m = this.id.match(/^modal_TempRowKey_(\d+)$/);
        if (m) {
            $("#modal_Title_" + m[1]).val(title);
        }
    }
});
于 2012-09-26T03:58:10.730 に答える