我想通过将其包含在另一个函数中来启动一个函数。在这种情况下,我想在执行print_help_A_0()
函数期间启动函数Check_Index()
:
$(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();
不起作用......
答案 0 :(得分:1)
你$(document).function没有用,因为你在$(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);
});