在JavaScript点击处理程序之间传递变量
如何在javaScript点击处理程序中传递变量 我已经分配了var条件选择=$this.val;in.changefunction。如何在第二个单击句柄中获取此变量的值,即启用$process signs报废按钮。单击函数{ 如何在这两个函数之间传递变量在JavaScript点击处理程序之间传递变量,javascript,jquery,arrays,Javascript,Jquery,Arrays,如何在javaScript点击处理程序中传递变量 我已经分配了var条件选择=$this.val;in.changefunction。如何在第二个单击句柄中获取此变量的值,即启用$process signs报废按钮。单击函数{ 如何在这两个函数之间传递变量 $('input:checkbox').change(function() { /*get the parent node of the radio and then hide only its siblings*/
$('input:checkbox').change(function() {
/*get the parent node of the radio and then hide only its siblings*/
$(this).parent('label').siblings().toggle();
if ($('.sign-condition').is(':checked')) {
var condition_selction = ($(this).val());
}
if ($('.sign-reason').is(':checked')) {
var reason_selction = ($(this).val());
}
//Check that both select fields have a value
if (condition_selction != null && reason_selction != null) {
$("#process-signs-scrap-scrapped-button-disabled").hide();
$("#process-signs-scrap-scrapped-button-enabled").show();
} else {
$("#process-signs-scrap-scrapped-button-disabled").show();
$("#process-signs-scrap-scrapped-button-enabled").hide();
}
});
$( "#process-signs-scrap-scrapped-button-enabled" ).click(function() {
var process_signs_scrap_condition = condition_selction;
var process_signs_scrap_reason = reason_selction
// Open the timer modal
$('#process-signs-scrap-scrapped-modal').modal('show');
全局声明这两个var,以便可以在这两个函数中访问它们
var condition_selction; // like this
var reason_selction;
$('input:checkbox').change(function() {
/*get the parent node of the radio and then hide only its siblings*/
$(this).parent('label').siblings().toggle();
if ($('.sign-condition').is(':checked')) {
condition_selction = ($(this).val()); // removed declaration
}
if ($('.sign-reason').is(':checked')) {
reason_selction = ($(this).val());
}
//Check that both select fields have a value
if (condition_selction != null && reason_selction != null) {
$("#process-signs-scrap-scrapped-button-disabled").hide();
$("#process-signs-scrap-scrapped-button-enabled").show();
} else {
$("#process-signs-scrap-scrapped-button-disabled").show();
$("#process-signs-scrap-scrapped-button-enabled").hide();
}
});
$( "#process-signs-scrap-scrapped-button-enabled" ).click(function() {
var process_signs_scrap_condition = condition_selction;
var process_signs_scrap_reason = reason_selction
// Open the timer modal
$('#process-signs-scrap-scrapped-modal').modal('show');
您可以将值传递给按钮上的数据属性,然后在单击按钮时访问数据属性及其good to go $'input:checkbox'.changefunction{ 如果“$”。符号条件“.”为“:已选中”{ var condition_selection=$this.val; $process signs报废按钮已启用。属性“数据值”,条件选择; } } $process signs报废按钮已启用。单击功能{ var condition_Selection=$this.attr'data-value'; console.log复选框的值为+条件选择; } 先点击我
单击“我最后一个”这两个函数的全局变量或变量范围是否相同?