我有以下(简化的)java 脚本、html 和包含的 java 脚本(js)文件。我的问题是我收到一个错误,即该方法在 syncData 函数调用中不存在。我知道我可以调用同步函数,因为它在 window.Main 的范围内,但是为什么我不能调用包含在 .js 脚本文件中的 syncData 以及如何调用它?
$(window).load(function () {
Main.init();
});
window.Main = {
sync: function () {
alert("sync");
},
init: function () {
var self = this;
self.displayDialog();
},
displayDialog: function () {
$("#dialog-confirm").dialog({
resizable: false,
height: 240,
width: 500,
modal: true,
buttons: {
"Sync Data": function () {
$(this).dialog("close");
Main.sync();
syncData();
},
Cancel: function () {
$(this).dialog("close");
alert("Cancel");
}
}
});
};
HTML:
<!DOCTYPE html>
<head>
<title>Pay Items Amounts</title>
<script src="Scripts/jquery-1.9.1.js" type="text/javascript"></script>
<script src="Scripts/jquery-ui-1.10.2.js" type="text/javascript"></script>
<!--<script src="Scripts/jquery.unobtrusive-ajax.js" type="text/javascript"></script>-->
<script src="Scripts/jquery.validate.js" type="text/javascript"></script>
<script src="Scripts/knockout-2.1.0.js" type="text/javascript"></script>
<script src="Scripts/modernizr-2.5.3.js" type="text/javascript"></script>
<script src="Scripts/PayItemAmounts.js" type="text/javascript"></script>
<script src="Scripts/spin.js" type="text/javascript"></script>
<script src="Scripts/syncData.js" type="text/javascript"></script>
<link href="Content/jquery-ui.css" rel="stylesheet" type="text/css" />
</head>
<body>
<header>
</header>
<nav>
</nav>
<section class="dialog-confirmation">
<div id="dialog-confirm" title="Sync Data?" style="display:none">
<p><span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>
<label id="dialog-message"></label> </p>
</div>
</section>
</body>
</html>
JAVASCRIPT syncData.js FILE:
syncData: function () {
alert("sync");
}