我收到語法錯誤。說我的代碼可能無法正常工作,直到我解決這個錯誤,但我沒有看到任何錯誤。錯誤行指向這個let weekAgo = new Date();
,但是這對我來說很合適。我可以忽略一些東西嗎這也會導致我的日期選擇器中的文本「from」和「to」不能自動顯示。任何幫助將不勝感激。JS函數語法與datepicker錯誤
該文本顯示在my fiddle,但由於某種原因不在我的應用程序。但該應用程序正在拋出該語法錯誤。所以任何幫助都會很好!
<script>
(function() {
//move these out since they don't need to
const today = new Date();
let weekAgo = new Date();
weekAgo.setDate(today.getDate() - 7);
const $from = $("#StartDate");
const $to = $("#EndDate");
$(function() { //DOM-loaded
//these don't change
const reportFields = $('#location, #locationbtns, #locationtextarea, #chosendates, #submitbtn, #formattype');
const employeeFields = $('#employeelist, #employeelistbtns, #employeelisttextarea');
const loc = $("#loc");
const EmployeeName = $("#EmployeeName");
const selectedElement = $('#selected');
const selected1Element = $('#selected1');
const reportType = $('#reporttype');
const generatereportform = $("form[name=generatereport]");
$(document).click(function(clickEvent) {
switch (clickEvent.target.id) {
case 'add':
setLocationOptionsSelected(true);
break;
case 'rem':
setLocationOptionsSelected(false);
break;
case 'add1':
setSelectedOnEmployeeOptions(true);
break;
case 'rem1':
setSelectedOnEmployeeOptions(false);
break;
}
});
$(document).change(function(changeEvent) {
switch (changeEvent.target.id) {
case 'reporttype':
handleReportTypeChange();
break;
case 'loc':
handleLocationChange();
break;
case 'EmployeeName':
handleEmployeeNameChange();
break;
}
});
function handleReportTypeChange() {
var value = reportType.val();
if (value === "checklistreports") {
generatereportform[0].reset();
reportFields.show();
loc.prop('required', true);
employeeFields.show();
generatereportform.attr("action", "index.cfm?content=reportsassociate");
EmployeeName.prop('required', true);
} else if (value === "locationreports") {
generatereportform[0].reset();
reportFields.show();
loc.prop('required', true);
employeeFields.hide();
generatereportform.attr("action", "index.cfm?content=reportslocation");
EmployeeName.prop('required', false);
} else {
generatereportform[0].reset();
reportFields.hide();
loc.prop('required', false);
employeeFields.hide();
generatereportform.attr("action", "#");
EmployeeName.prop('required', false);
}
resetDatePickers();
}
function dateSelectHandler(dateText) {
if (this.id == 'StartDate') {
$to.datepicker("option", "minDate", dateText);
} else {
$from.datepicker("option", "maxDate", dateText);
}
}
function resetDatePickers() {
let datePickerConfig = {
changeMonth: true,
maxDate: today,
onSelect: dateSelectHandler
};
$from.datepicker(datePickerConfig).datepicker('setDate', weekAgo);
$to.datepicker(Object.assign(datePickerConfig, {
minDate: weekAgo
})).datepicker('setDate', today);
}
function handleLocationChange() {
var selected = [];
loc.find("option:selected").each(function() {
selected.push($(this).text());
});
selectedElement.val(selected.join("\n"));
}
function setLocationOptionsSelected(selected) {
loc.find("option").prop("selected", selected);
loc.change();
}
function setSelectedOnEmployeeOptions(selected) {
EmployeeName.find("option").prop("selected", selected);
EmployeeName.change();
}
function handleEmployeeNameChange() {
var selected = [];
EmployeeName.find("option:selected").each(function() {
selected.push($(this).text());
});
selected1Element.val(selected.join("\n"));
}
});
})();
</script>
你所提到的行語法錯誤點,但語法錯誤實際上說了什麼? –
所有的dreamweaver所說的是該行的語法錯誤。 「代碼提示可能無法正常工作,直到你解決這個錯誤。」 –
'const today = new Date();'你在哪個瀏覽器上運行,。 'const'是ES6。 – Keith