我有一个表单,上面有星期几按钮,然后单击按钮,我将所选按钮传递给确认模式
,并且所有这些工作正常。我遇到的问题是,如果我关闭我的模式
,填充我的字段,然后尝试重新提交,我会不断收到错误
.join is not a function
JQuery
var selectedWkDays = [ ];
var selectedMthDays = [ ];
var selectedMths = [ ];
$('#submitButton').click(function () {
getSelectedWeekdayValues();
getSelectedDaysOfMonthValues();
getSelectedMonthValues();
$("b[name = 'modalDialPlanTelNo']").html($('#dialPlanTelNo').html());
if (pageState == 'Inactive' && buttonclicked == 'Add') {
$('#inactiveAddSuccessModal').modal();
addModifyRuleFieldSelections();
// Sets focus to 'Add More Rules' button once modal loaded
$('#inactiveAddSuccessModal').on('shown.bs.modal', function () {
$('#addMoreRulesButton').focus();
})
} else if (pageState == 'Active') {
$('#activeAddSuccessModal').modal();
if (buttonclicked == 'Add') {
$("#addedupdatedtext").html('added');
$('#addedLastSentence').css("display", "block");
$('#addAnotherRuleButton').css("display", "inline");
} else {
$("#addedupdatedtext").html('updated');
$('#addedLastSentence, #addAnotherRuleButton').css("display", "none");
}
addModifyRuleFieldSelections();
// Sets focus to 'Close' button once modal loaded
$('#activeAddSuccessModal').on('shown.bs.modal', function () {
$('#modalCloseButton').focus();
})
}
});
// Creates an array for the selected weekdays to pass to modal
function getSelectedWeekdayValues(){
/* looks for all weekday buttons and check if it was selected */
$("#selectWeekdaysSection .btn-primary").each(function() {
selectedWkDays.push($(this).val());
});
/* joins the array which is separated by the comma */
var wkDaysSelected;
wkDaysSelected = selectedWkDays.join(', ');
/* checks if there is selected buttons, by default the length is 1 as it contains one single comma */
if(wkDaysSelected.length > 0){
/* converts the wording if all weekday buttons selected */
if (wkDaysSelected == "Mon, Tue, Wed, Thur, Fri, Sat, Sun") {
wkDaysSelected = "All days";
} else if (wkDaysSelected == "Mon, Tue, Wed, Thur, Fri") {
wkDaysSelected = "Weekdays only";
} else if(wkDaysSelected == "Sat, Sun") {
wkDaysSelected = "Weekends only";
} else {
wkDaysSelected = wkDaysSelected;
}
} else {
/* if no days where selected, sets the default to 'All days' */
wkDaysSelected = "All days";
}
selectedWkDays = wkDaysSelected;
}
// Ccreates an array for the selected days of the month to pass to modal
function getSelectedDaysOfMonthValues(){
/* looks for all days of the month buttons and check if it was selected */
$("#selectDaysOfMonthsSection .btn-primary").each(function() {
selectedMthDays.push($(this).val());
});
/* joins the array which is separated by the comma */
var mthDaysSelected;
mthDaysSelected = selectedMthDays.join(', ') ;
/* checks if there is selected buttons, by default the length is 1 as it contains one single comma */
if(mthDaysSelected.length > 0){
/* converts the wording if all days of the month buttons selected */
if(mthDaysSelected == "01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31") {
mthDaysSelected = "All days of the month";
} else {
mthDaysSelected = mthDaysSelected;
}
} else {
/* if no days where selected, sets the default to 'All days of the month' */
mthDaysSelected = "All days of the month";
}
selectedMthDays = mthDaysSelected;
}
// Creates an array for the selected months to pass to modal
function getSelectedMonthValues(){
/* looks for all days of the month buttons and check if it was selected */
$("#selectMonthsSection .btn-primary").each(function() {
selectedMths.push($(this).val());
});
/* joins the array which is separated by the comma */
var mthsSelected;
mthsSelected = selectedMths.join(', ') ;
/* checks if there is selected buttons, by default the length is 1 as it contains one single comma */
if(mthsSelected.length > 0){
/* converts the wording if all days of the month buttons selected */
if(mthsSelected == "Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sept, Oct, Nov, Dec") {
mthsSelected = "All months";
} else {
mthsSelected = mthsSelected;
}
} else {
/* if no days where selected, sets the default to 'All months' */
mthsSelected = "All months";
}
selectedMths = mthsSelected;
}
$('#activeButton, #addAnotherRuleButton, #addMoreRulesButton, #modalCloseButton').click(function () {
if (this.id != 'activeButton') {
location.reload();
}
$('#activeButton').addClass('btn-primary');
$('#inactiveButton').removeClass('btn-primary');
$('#inactiveButton').addClass('btn-default');
active();
pageState = 'Active';
});
// Active button function to set HTML attributes
var active = function () {
$("#activeInactiveHeader").html('Active');
$("button[name = 'modifyButton'], button[name = 'deleteButton']").css("display", "block");
$("#orderPositionRow, #callRangeRow").css("display", "block");
defaults();
}
var defaults = function () {
$("#todrexitingrules, #ruleBuilder, #initialAddTip, #dateErrorMessage").css("display", "none");
}
最佳答案
完成贾罗德的回答。
您可以返回值,而不是将字符串设置到数组中。您可以将数组声明到函数中。
function getSelectedWeekdayValues(){
var selectedWkDays = [ ];
[...]
return wkDaysSelected;
}
并且在您的点击事件中,您可以使用返回值设置一个全局变量
var selectedWeekdayValues;
$('#submitButton').click(function () {
selectedWeekdayValues = getSelectedWeekdayValues();
关于javascript - 单击按钮时显示 .JOIN JQuery 错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54748569/