论坛首页 Web前端技术论坛

prototype event 的错误

浏览 2831 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2007-04-28  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script type="text/javascript" src="js/prototype.js"></script>
<script language="javascript">

	Event.observe('123', 'click', function(event) {
		//var elt = Event.element(event);
		alert('elt');
	});	
</script>
<title>测试</title>
</head>

<body>
<p id="123">sdfasdfafasf</p>
</body>
</html>


然后firefox报了如下的错误:

错误: element has no properties
源文件:file:///E:/doc/test/js/prototype.js
行:2239

大家有遇到这个问题么?

   发表时间:2007-04-28  
补充下,prototype是1.5.0的
0 请登录后投票
   发表时间:2007-04-28  
页面没有初始化好 你就 执行 js 了 当然会错

一般写 body 的 onload 或者

Event.observe(window, 'load', function(){
    Event.observe('123', 'click', function(event) {  
        alert('elt');  
    });  
})


另外
script 用 type 不要用 language
id 不要用数字开头
0 请登录后投票
论坛首页 Web前端技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics