2014-02-17 27 views
0

我想通过将函数包含在另一个函数中来启动函数。在这种情况下,我想Check_Index()功能时启动功能print_help_A_0()正在执行:将函数执行到另一个函数中

$(function() { 
    $(document).on('click', '#Demeler', Check_Index); 
    $(document).on('click', '#Hasard', Check_Index); 

    function Check_Index() { 

     var choixA = $('#ChoixA').val().toUpperCase(); 
     var choixA_l = choixA.length; 
     var choixB = $('#ChoixB').val().toUpperCase(); 
     var choixB_l = choixB.length; 

     if(choixA_l == 0 & choixB_l == 0){$('#ChoixA').focus();} 
     [...] 
     else if(choixA != choixB){ 
      var id = $(this).attr('id'); 
      if(id == "Demeler"){ 
       //run my function print_help_A_0() 
      }else if(id ="Hasard"){[...]} 
     } 
    }; 

    function print_help_A_0() {   
     var bulle_help_A_0 = <?php echo json_encode(get_option('bulle_help_A_0')); ?>; 
     var bulle_misska = $('#misska').qtip({ 
       content: {text: bulle_help_A_0+'<input type="button" value="go !" id="print_help_A_1"/>'}, 
       style: {classes: 'qtip-light'}, 
       position: {my: 'right center',at: 'center left'}, 
     show: 'none',hide:'none' 
    }); 
    var api_bulle_misska = bulle_misska.qtip('api'); 
    api_bulle_misska.show(); 
    };  
}); 

当我写[...],它只是为了简化我的代码。

有什么想法?因为$(document).print_help_A_0();不起作用...

+1

只是'print_help_A_0();' –

+0

是它的上,它更容易和^^ – Muramasa

回答

1

您$(document).function不起作用,因为您在$(function(){})中声明了函数,在文档级声明,只将初始化代码放入$(函数(){}),例如:

function Check_Index() { 

    var choixA = $('#ChoixA').val().toUpperCase(); 
    var choixA_l = choixA.length; 
    var choixB = $('#ChoixB').val().toUpperCase(); 
    var choixB_l = choixB.length; 

    if(choixA_l == 0 & choixB_l == 0){$('#ChoixA').focus();} 
    [...] 
    else if(choixA != choixB){ 
     var id = $(this).attr('id'); 
     if(id == "Demeler"){ 
      print_help_A_0() 
     }else if(id ="Hasard"){[...]} 
    } 
}; 

function print_help_A_0() {   
    var bulle_help_A_0 = <?php echo json_encode(get_option('bulle_help_A_0')); ?>; 
    var bulle_misska = $('#misska').qtip({ 
      content: {text: bulle_help_A_0+'<input type="button" value="go !" id="print_help_A_1"/>'}, 
      style: {classes: 'qtip-light'}, 
      position: {my: 'right center',at: 'center left'}, 
      show: 'none',hide:'none' 
    }); 

    var api_bulle_misska = bulle_misska.qtip('api'); 
    api_bulle_misska.show(); 
}; 

$(function() { 
    $(document).on('click', '#Demeler', Check_Index); 
    $(document).on('click', '#Hasard', Check_Index);  
}); 
相关问题