类型错误,而不是函数
我已经继承了一些Javascript,这个JS曾经工作过,但由于某种原因它不再有效。类型错误,而不是函数
我有以下脚本,请记住我斩下来,只列出违规的部分:
function top_frame() {
top_frame = top.frames[0].document;
top_frame.write('<HTML><BODY topmargin=0 leftmargin=0 marginheight=0 marginwidth=0><IMG SRC="'+image_url+'/options_top.gif" HEIGHT=25 WIDTH=300></BODY></HTML>')
// top_frame.write('<HTML><BODY BGCOLOR="#339999"><IMG SRC="images/global/options_top.gif" WIDTH=300 HEIGHT=25 ALT="Product options editor" BORDER="0"></BODY></HTML>')
top_frame.close();
}
function bottom_frame() {
bottom_frame = top.frames[2].document;
bottom_frame.write('<HTML><BODY topmargin=0 leftmargin=0 marginheight=0 marginwidth=0><A HREF="javascript:top.update_options()"><IMG SRC="'+image_url+'/options_end.gif" WIDTH=300 HEIGHT=30 ALT="Update and close" BORDER="0"></A></BODY></HTML>')
bottom_frame.close();
}
</SCRIPT>
<frameset rows="26,*,31" frameborder="NO" border="0" framespacing="0">
<frame src="javascript:top.top_frame()"
scrolling="NO" marginwidth="0" marginheight="0" frameborder="NO"
NAME="options_top">
<frame src="javascript:top.show_start()"
marginwidth="0" marginheight="0" frameborder="NO" scrolling="auto"
NAME="options_main">
<frame src="javascript:top.bottom_frame()"
scrolling="NO" marginwidth="0" marginheight="0" frameborder="NO"
NAME="options_bottom">
</frameset>
</HTML>
我调用的函数bottom_frame()
,show_start()
和top_frame()
页面底部的HTML。但是,我在错误标签中看到以下消息:
TypeError: top.bottom_frame is not a function
我在每个函数调用中都看到了这一点。任何人都可以提出什么问题在这里?
bottom_frame()
未在顶部对象上定义。您在全球范围内定义它,所以请拨打top
。因此,而不是:
top.bottom_frame()
就叫
bottom_frame()
'top'指的是顶部'窗口'所以在这边所有好的 – Grundy
谢谢,但是这样做会返回错误:“bottom_frame()未定义。” –
不要为你已经使用了函数名
例如变量使用相同的名称,如果你定义一个function a
为
function a(){a =1};
并调用这个a()
,它会输出1;
但下一次会给出错误
Uncaught TypeError: a is not a function
,因为它被执行时重新定义a
到non-function
类型值即1
这里'函数bottom_frame(){ bottom_frame =顶部。 frames [2] .document;'你重新定义了从函数到文档的'bottom_frame'。所以,这段代码第一次工作,然后失败 – Grundy