如何在javaScript中傳遞變量單擊處理程序。在JavaScript單擊處理程序之間傳遞變量
我已將var condition_selction = ($(this).val());
分配給.change(function)
。我如何在第二個點擊句柄$("#process-signs-scrap-scrapped-button-enabled").click(function() {
中獲得這個變量的值。
我如何在這兩個函數之間傳遞變量。
$('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');
什麼相同的兩個二元函數的全局變量或變量範圍是什麼? –