【发布时间】:2015-04-22 09:38:35
【问题描述】:
单击触发 change_type 函数的单选按钮时出现以下错误:
Uncaught ReferenceError: customerType is not defined
我正在使用以下代码:
var date_selected = false;
var selected_year = false;
var current_customer = false;
var current_type = false;
var previous_value = 0;
var temp = <?php print_r($json); ?>;
var part = temp['Particulier'];
//console.log(part);
var type = part['Weekend'];
//console.log(type);
var yearArray = type['2016'];
//console.log(yearArray);
var dateSelect = document.getElementsByClassName('dateSelect');
var yearLabel = $("label[for='year']");
var year = document.getElementById('year');
var month = document.getElementById('month');
var date = document.getElementById('date');
$(dateSelect).hide();
yearLabel.hide();
function change_customer(value) {
current_customer = value;
var customerType = temp[value];
console.log(customerType);
}
function change_type(value) {
$(dateSelect).show();
yearLabel.show();
current_type = value;
if(previous_value == 0) {
$(dateSelect).show();
}
if(current_type == 'Weekend') {
year.selectedIndex = 0;
month.style.visibility = 'hidden';
date.style.visibility = 'hidden';
} else if(current_type == 'Midweek') {
year.selectedIndex = 0;
month.style.visibility = 'hidden';
date.style.visibility = 'hidden';
} else if(current_type == 'Week') {
year.selectedIndex = 0;
month.style.visibility = 'hidden';
date.style.visibility = 'hidden';
}
previous_value = value;
var dateType = customerType[value];
console.log(dateType);
}
如果需要任何其他信息,请询问,新手,以及 jQuery。 提前致谢!
【问题讨论】:
-
您已在 change_customer 函数中将 customerType 变量声明为私有变量,并在其他函数中访问它
-
W3Schools 从来没有用处。