0

私は完全に正常に動作している次のスクリプトを持っています。2 つのフィールドで何らかの計算を行い、3 番目のフィールドに表示します。

     $(function() {
     $(document).on('change', 'td.evaluation select', function() {
        var gap = parseInt($(this).find(':selected').val())- parseInt($(this).parents('tr').find('td.mefly').text()) ;

        $(this).parents('tr').find('td.gap input:text').val(gap);
        if(gap<0){
         $(this).parents('tr').find('td.gap input:text').css('background-color','red');
        }else  $(this).parents('tr').find('td.gap input:text').css('background-color','#3CB371');

     });
  });

ここで、以前に保存された値を使用して、ページの読み込み時にスクリプトを実行するスクリプトを追加したいと考えました。しかし、それは結果を空白のままにします。これが私が試したものです:

        $(document).ready(function(){

            var gap = parseInt($("td.evaluation select").find(':selected').val())- parseInt($("td.evaluation select").parents('tr').find('td.mefly').text()) ;

            $("td.evaluation select").parents('tr').find('td.gap input:text').val(gap);
            if(gap<0){
                $("td.evaluation select").parents('tr').find('td.gap input:text').css('background-color','red');
            }else  $("td.evaluation select").parents('tr').find('td.gap input:text').css('background-color','#3CB371');

        }

    )};

私は何を間違えましたか?

4

0 に答える 0