[英]javascript error: object not defined
我正在尝试重用我在另一页上工作过的某些脚本,但是此脚本始终出现错误。
我有一个名为CalendarPopup.js的.js文件。 它像这样链接到我的HTML:
<script type="text/javascript" src="/administrator/components/com_arrcard/js/CalendarPopup.js"></script>
这是一个JavaScript库,显示了一个弹出日历,用户单击链接时可以选择日期。 然后将值放入字段。 这是显示字段和链接的代码:
<tr id="birthDate">
<td align="left" valign="top">
<script type="text/javascript">
var calStart = new CalendarPopup("calendar");
calStart.showNavigationDropdowns();
</script>
Birth Date:
</td>
<td>
<input style="width:124px;" type="text" name="birthdate" value="" />
<a href="#" onclick="calStart.select(document.instantForm.birthdate,'anchorBirthdate','MM/dd/yyyy'); return false;" id="anchorBirthdate">select</a>
</td>
</tr>
然后有一个div实际上持有日历:
<div id="calendar" style="position:absolute;visibility:hidden; background-color:white; layer-background-color:white;"></div>
所有这些在一页上都可以完美地工作,但是在新的一页上,我遇到了错误
CalendarPopup is not defined
在这条线上:
var calStart = new CalendarPopup("calendar");
我想念什么? 我确定这是非常明显的事情,但我已经盯着它看了太长时间而且看不到它。
您可以向窗口添加一个事件侦听器,并在加载后执行使用.js文件的代码。
//Some js file
window.addEventListener('load',onload,false);
function onload(){
var x = new yourObject();
}
您当前正在加载它之前调用它,因此对象未定义错误。
确保定义CalendarPopup类的脚本位于任何其他javascript引用之前执行它的位置。
问题很可能是您的javascript文件的加载顺序。
将<script>
包含标记放在<head>
,就可以了。
如果你的js文件的来源与http://www.mattkruse.com/javascript/calendarpopup/source.html相同,那就说你必须包含其他三个js文件
AnchorPosition.js
date.js
PopupWindow.js
谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.