我有外部javascript文件。我的要求是在视图上访问外部JS变量。在这里,我附上了我的Js来源,
var tdDetailList = [];
dateFormat: "mm/dd/yyyy",
(function ($) {
$.extend($.ui, { multiDatesPicker: { version: "1.6.4"} });
$.fn.multiDatesPicker = function(method) {
var mdp_arguments = arguments;
var ret = this;
var today_date = new Date();
var day_zero = new Date(0);
var mdp_events = {};
function removeDate(date, type) {
if(!type) type = 'picked';
date = dateConvert.call(this, date);
for (var i = 0; i < this.multiDatesPicker.dates[type].length; i++)
if (!methods.compareDates(this.multiDatesPicker.dates[type][i], date))
{
this.multiDatesPicker.dates[type].splice(i, 1).pop();
window.tdDetailList.splice(i, 1).pop();
}
return this.multiDatesPicker.dates[type].sort(methods.compareDates);
}
function removeIndex(index, type) {
if(!type) type = 'picked';
return this.multiDatesPicker.dates[type].splice(index, 1).pop();
}
function addDate(date, type, no_sort) {
if (!type) type = 'picked';
date = dateConvert.call(this, date);
// @todo: use jQuery UI datepicker method instead
date.setHours(0);
date.setMinutes(0);
date.setSeconds(0);
date.setMilliseconds(0);
var a = date.toLocaleDateString("en-US");
if (methods.gotDate.call(this, date, type) === false) {
this.multiDatesPicker.dates[type].push(date);
window.tdDetailList.push(date.toLocaleDateString("en-US"));
if (!no_sort) this.multiDatesPicker.dates[type].sort(methods.compareDates);
}
}
我的Html有脚本
$('#Save').click(function () {
var x = document.getElementById("roomId").value;
if (x == '') {
alert("Please select room Id");
}
else
{
var url = "/Home/SaveToDatabase";
$.post(url, { "unabailableList.UnavailableDates": window.tdDetailList, "unabailableList.RoomID": x }, function (data) {
alert(data);
});
}
})
此脚本在IE上正常运行但在Chrome上无法运行。在chrome中有一条错误消息&#34; tdDetailList&#34;未定义。请帮我解决这个问题。我想在视图
上从外部JS访问变量