请教这个js为什么没有效果 我写在div里面有效果,为什么写在外面就没有效果了,请各位大佬帮忙。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 windows.laload()是什么?你togreen和tored两个函数要放到全局环境中,不能放别的函数中。 那个应该是windows.onload(),我写错了 只有window没有windows,写在div里面是注册了事件,写在外面你没有注册事件 id = "div1",你div1不加引号是没有效果的 全局环境?那是指放在哪里就是让你去掉windows.onload(){}。再说你设置onload事件的语法也不对。如要设置onload事件应该是window.onload = function(){}注意window后面没有s <!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <style> </style></head><body> <div id="div1" style="width:200px;height:200px; background-color:orange;"></div></body></html> window.onload = function () { addEvent(document.getElementById('div1'), 'mouseenter', function () { this.style.width = '300px'; this.style.height = '300px' this.style.backgroundColor = 'red'; }); addEvent(document.getElementById('div1'), 'mouseout', function () { this.style.width = '200px'; this.style.height = '200px'; this.style.backgroundColor = 'blue'; }); } var addEvent = document.addEventListener ? function (el, type, callback) { el.addEventListener(type, callback, !1); } : function (el, type, callback) { el.attachEvent("on" + type, callback); };要简单的话用jQuery来绑定吧 如何把jsp中的时间存储在数据库 图片缓慢加载实例中问题 挑战你的智慧(我想让方框从右测冒出来,并且浏览器下面不出现横向滚动条,怎做到?) 请教几个问题 散分,祝大家元旦快乐! 如何让iframe全屏/正常状态切换 求一段正则表达式,谢谢 关于用层模拟的下拉菜单被遮挡的问题求助 automation服务器不能创建对象,为什么?请指点! 下面出错???:<input type=button name=min value=min onclick="window.moveto(1000,2000)"> npm安装淘宝镜像出错,网上搜索了一下找不到类似问题的解决办法,求大神帮助 前端排序求思路
就是让你去掉windows.onload(){}。再说你设置onload事件的语法也不对。
如要设置onload事件应该是
window.onload = function(){}
注意window后面没有s
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style>
</style>
</head>
<body>
<div id="div1" style="width:200px;height:200px; background-color:orange;"></div>
</body>
</html> window.onload = function () {
addEvent(document.getElementById('div1'), 'mouseenter', function () {
this.style.width = '300px';
this.style.height = '300px'
this.style.backgroundColor = 'red';
});
addEvent(document.getElementById('div1'), 'mouseout', function () {
this.style.width = '200px';
this.style.height = '200px';
this.style.backgroundColor = 'blue';
});
}
var addEvent = document.addEventListener ? function (el, type, callback) {
el.addEventListener(type, callback, !1);
} : function (el, type, callback) {
el.attachEvent("on" + type, callback);
};要简单的话用jQuery来绑定吧