1

この配列に何か問題がありますか?

//loading_image is hidden at first
$('#run_only').click(function(e) {
  $('#loading_image').show();
  var def_main = false,
      def_header = false,
      def_iostream = false,
      def_conio = false,
      def_stdio = false,
      def_math = false,
      def_string = false;

  //REMOVE PREVIOUSLY ADDED CLASSESS TO LN
  $('#board_ln').contents().removeClass('line-error');
  if(er_syntax_pre) {
    var error_text = '<p>Syntax Error. Detected brace matching error.</p>';
    var debugging_text = '<p>DEBUGGING: Check the proper pairing of ( ), { }, [ ], \' \', " " </p>';

    mb_error(error_text, debugging_text);
  } else {
    mb_noerror('');//transfer this at the end part later
    var inlineDiv_num = $('#board_code > div ').size(),
        kword_search_raw="",
        kword_search="",
        kwordSyntaxSearch_tilde="",
        kwordSyntaxSearch="",
        noKeyword = true
    er_text = new Array(),
    er_ln = new Array(),
    er_debug_text = new Array();

    er_text = [];
    er_ln = []; 
    er_debug_text = [];

    for( var x=0; x<inlineDiv_num; x++ ) {
      var inlineDiv_num_textL = $('#board_code > div ').eq(x).text().length,
          inlineDiv_num_text = $('#board_code > div ').eq(x).text();

      for( var y=0; y<inlineDiv_num_textL; y++) {
        //kword_search = kword_search + inlineDiv_num_text.charAt(y); 
        kword_search_raw = kword_search_raw + inlineDiv_num_text.charAt(y);
        kword_search = kword_search + inlineDiv_num_text.charAt(y); 

        //SEARCH FOR STRINGS AND REPLACE THEM
        if(/(?:'[^']+'|"[^"]+")$/.test(kword_search)) {
          //alert('found 2nd occurence of quote');
          kword_search = kword_search.replace(/(?:'[^']+'|"[^"]+")$/, "!string!");
        }
        //alert(kword_search);
        //include***********
        if(/\s*\#include$/.test(kword_search) ) {
          noKeyword = false;
          //alert('at the tail of #include');

          var kwordSyntaxSearch = sliceToEndString(x,y);

          //alert('kwordSyntaxSearch: '+kwordSyntaxSearch);

          //SYNTAX CHECKER
          if( /^\s*<\s*iostream\.h\s*>*/.test(kwordSyntaxSearch) ) {
            def_iostream = true;
            var charLast = kwordSyntaxSearch.indexOf(">");
            kwordSyntaxSearch_tilde = kwordSyntaxSearch.splice(charLast+1, 0, "~~");
          } else if( /^\s*<\s*conio\.h\s*>*/.test(kwordSyntaxSearch) ) {
            def_conio = true;
            var charLast = kwordSyntaxSearch.indexOf(">");
            kwordSyntaxSearch_tilde = kwordSyntaxSearch.splice(charLast+1, 0, "~~");
          } else if( /^\s*<\s*stdio\.h\s*>*/.test(kwordSyntaxSearch) ) {
            def_stdio = true;
            var charLast = kwordSyntaxSearch.indexOf(">");
            kwordSyntaxSearch_tilde = kwordSyntaxSearch.splice(charLast+1, 0, "~~");
          } else if( /^\s*<\s*string\.h\s*>*/.test(kwordSyntaxSearch) ) {
            def_string = true;
            var charLast = kwordSyntaxSearch.indexOf(">");
            kwordSyntaxSearch_tilde = kwordSyntaxSearch.splice(charLast+1, 0, "~~");
          } else if( /^\s*<\s*math\.h\s*>*/.test(kwordSyntaxSearch) ) {
            def_math = true;
            var charLast = kwordSyntaxSearch.indexOf(">");
            kwordSyntaxSearch_tilde = kwordSyntaxSearch.splice(charLast+1, 0, "~~");
          } else {
            //alert('#include syntax error');
            er_text.push('Error: Syntax | Runtime. #include<headerfile.h>');
            er_debug_text.push('Debugging: (1)Check text after "#include" (2)Check "support" for supported libraries');
            er_ln.push(x);
            y=inlineDiv_num_textL;
            x=inlineDiv_num;
          }//else
        }//IF FOUND #INCLUDE|
      }//for y
    }//for x
    //NO KEYWORDS AT ALL
    if(noKeyword){
      er_text[0] = "Error: No keywords detected";
      er_debug_text[0] = "Debugging: Make sure that you are using the supported C++ keywords of this system";
      er_ln[0] = inlineDiv_num-1;
      mb_error(er_text[0], er_debug_text[0], er_ln[0]); 
    }
    if(er_ln.length > 0) {
      mb_error(er_text[0], er_debug_text[0], er_ln[0]);
    }
  }//else no brace error        

  $('#loading_image').hide();
});

このコードでは gif 画像が表示されません。$('#loading_image').hide(); を削除してみました そして、「長いコード処理」の後に画像の読み込みが行われることを発見しました

4

2 に答える 2

1

これは、推論するのが難しい非同期プログラミングの 1 つの側面です。次の例を検討してください。

$('#run_only').click(function(e) {
    $('#loading_image').show();

    $.getJSON('/something.json?wait=3seconds', function() {
      //This code will take about 3 seconds to execute
    });

    //This code will execute as soon as the $.get is fired (before it has returned)
     $('#loading_image').hide();
});

これを修正するには、次のようにしてください。

$('#run_only').click(function(e) {
    $('#loading_image').show();

    $.getJSON('/something.json?wait=3seconds', function() {
      //This code will take about 3 seconds to execute
     //But this will only execute after the $.getJSON() is sucessful
     $('#loading_image').hide();
    });
});
于 2013-08-20T16:41:00.393 に答える