请问元素对象的事件名是否可写成变量,火狐可以,不知道ie如何写 var box=document.getElementById('div01');var type='onclick';box[type]=function(e){ alert('here!')} 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我今天才发现ie难道不能这么写吗?var obj=document.getElementById('div01'); obj.onclick=function(){ alert(1)} 都可以啊 ie7dao9试了下没问题啊 IE试下用box.attachEvent(type , function(e){ alert('here!')}); 恩 这个我知道,正好前段研究来着。但下面这个在ie下不行吗?还是我电脑出问题了??var obj=document.getElementById('div01'); obj.onclick=function(){ alert(1) } <!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" /><title>无标题文档</title><script type="text/javascript"> function init(){ var obj=document.getElementById('test1'); obj.onclick=function(){ alert(1) } } window.onload=init;</script></head><body><div id="test1">11</div></body></html>试了下可以啊 你看看有没有在其他地方给这个元素加onclick事件啊 有的话会被覆盖 多谢zzgzzg00,你这么写我这可以! 但我这么写,我把js写在了html下面了,先加载的html,这样不可以啊<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>12</title><style></style><div id="div01" style="background:yellow; width:100px; height:100px" ></div><script language="javascript" >var obj=document.getElementById('div01'); obj.onclick=function(){ alert(1) }</script></body></html> 我这么写 var obj=document.getElementById('div01'); alert(obj) 显示null,元素都没取到。 点击后改变字体颜色 getElementByTagName 换成 JQuery怎么写? 在ext的formPanel中如何实现文件下载 关于如何返回上次访问过的页面的问题 这种a:hover怎么弄? 问一个有关按钮点击出错的问题,高手看看!xie xie le 简单问题 到时间自动提交试卷的函数,请教有效性 如何打开一个没有标题的窗口? 一图形区域能同时实现onclick,onmouseover,onmouseout三个事件吗??? 有关超链接的问题!! 太简单了,就是没能解决....... XMLHttpRequest 传送参数中的特殊字符 js 如何实现div层的下滑,覆盖下面的那个层
obj.onclick=function(){
alert(1)
}
box.attachEvent(type , function(e){
alert('here!')
});
恩 这个我知道,正好前段研究来着。
但下面这个在ie下不行吗?还是我电脑出问题了??var obj=document.getElementById('div01');
obj.onclick=function(){ alert(1) }
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
function init(){
var obj=document.getElementById('test1');
obj.onclick=function(){ alert(1) }
}
window.onload=init;
</script>
</head><body>
<div id="test1">11</div>
</body>
</html>试了下可以啊 你看看有没有在其他地方给这个元素加onclick事件啊 有的话会被覆盖
但我这么写,我把js写在了html下面了,先加载的html,这样不可以啊
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>12</title>
<style>
</style>
<div id="div01" style="background:yellow; width:100px; height:100px" ></div>
<script language="javascript" >
var obj=document.getElementById('div01');
obj.onclick=function(){ alert(1) }
</script>
</body>
</html>
var obj=document.getElementById('div01');
alert(obj)
显示null,元素都没取到。