[英]In the script the data is coming from server but not initialized into variables
<script type="text/javascript" language="javascript">
$(document).ready(function () {
var _dateFormat = '';
_dateFormat = '<%= WebUI.Models.WebConfigKeys.DateFormat %>';
var dateArray = '<%= ViewData["CompareCollectionDateSvc"] %>';
var enabledDays = new Array();
enabledDays = dateArray.split(",");
var _firstVal = enabledDays[0];
var _LastVal = enabledDays[4];
GetCalederLoad(_firstVal, _LastVal, _dateFormat);
function GetCalederLoad(startDt, endDt, dtFormat) {
if (dtFormat != undefined && dtFormat != "")
dtFormat = dtFormat.toLowerCase();
$("#drpNewCollectionDateSvc").datepicker({
autoclose: true,
clearBtn: true,
startDate: startDt, // '(System.Web.Mvc.SelectList)(ViewData["CollectionDate"]).First();', //firstarrdate,
endDate: endDt, // '(System.Web.Mvc.SelectList)(ViewData["CollectionDate"]).Last();',// lastarrdate,
format: dtFormat,
daysOfWeekDisabled: [0, 6],
Default: false,
beforeShowDay: function (Date) {
var curr_date = Date.toJSON().substring(0, 10);
}
});
}
});
</script>
在此腳本中,我從ViewData
或WebConfig中的服務器獲取數據,但未將其設置為其他變量。 我收到一個錯誤:
名稱“ _dateformat”在當前上下文中不存在
您的輸出如下:
var dateArray = '07/05/2016,07/06/2016,07/07/2016,07/08/2016,07/11/2016';
然后,您可以使用以下命令:
var _dateFormat = ''; //_dateFormat = '<%= WebUI.Models.WebConfigKeys.DateFormat %>'; _dateFormat = 'MM-dd-yyyy'; //var dateArray = '<%= ViewData["CompareCollectionDateSvc"] %>'; var dateArray = '07/05/2016,07/06/2016,07/07/2016,07/08/2016,07/11/2016'; dateArray = dateArray.split(','); console.log(dateArray); var _firstVal = dateArray[0]; console.log(_firstVal); var _LastVal = dateArray[4]; console.log(_LastVal);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.