问题一:var out=function(){}与 function out(){}区别
例
<!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><script type="text/javascript">
var change=function(obj){
var obj=document.getElementById(obj);
obj.style.backgroundColor="#CFDBEC";
obj.onmouseout=out
var out=function(){
obj.style.backgroundColor="#A9EE23";
}
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
#apDiv1 {
position:absolute;
width:200px;
height:115px;
z-index:1;
border:1px solid #C0C;
}
</style>
</head>
<body>
<div id="apDiv1" onclick="change('apDiv1')"></div>
</body>
</html>
这种情况下out函数不能执行,应该是好没有加载到out所以out没有定义,为什么改成function out(){}的形式就可以运行?
或者
我将obj.onmouseout=out改成 obj.onmouseout=function(){out()}也可以为什么,这两种写法解释上有什么区别?
例
<!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><script type="text/javascript">
var change=function(obj){
var obj=document.getElementById(obj);
obj.style.backgroundColor="#CFDBEC";
obj.onmouseout=out
var out=function(){
obj.style.backgroundColor="#A9EE23";
}
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
#apDiv1 {
position:absolute;
width:200px;
height:115px;
z-index:1;
border:1px solid #C0C;
}
</style>
</head>
<body>
<div id="apDiv1" onclick="change('apDiv1')"></div>
</body>
</html>
这种情况下out函数不能执行,应该是好没有加载到out所以out没有定义,为什么改成function out(){}的形式就可以运行?
或者
我将obj.onmouseout=out改成 obj.onmouseout=function(){out()}也可以为什么,这两种写法解释上有什么区别?
解决方案 »
- 求助.Extjs4 Grid 分页
- 禁止输入的字符中含有--
- 网页里播放avi,wmv,rm,mov等视频,请问如何用脚本控制播放,暂停,快进,快退,以及音量等,最好能有相关的资料。
- 怎样用一个函数使多个iframe自动调整高度?
- javascript中的iframe问题
- 如何通过一个DIV里面的Label标签来获取它所在的DIV的ID
- 各位高手帮助!!急急。在线等待!!
- 给CSDN化妆
- 一个很弱智的问题:在javascript中,一个变量名怎样包含另一个变量名,如vbscript中可用 title_name"&i&"
- request.getParameterValues()取不到值
- 如何解决无法访问google导致的页面问题
- 在线等,解决了就贴。EXTJS怎么设置窗体上控件的位置呢?
这个在预编译的时候不一样.
前者在预编译时 定义成undefined
后者在预编译时 定义成一个函数
var out=function(){
obj.style.backgroundColor="#A9EE23";
}
obj.onmouseout=out
将这个换一下位置就行了;
就想一楼所说
js 是按顺序执行的;如果遇到 变量是就去产看 是否是属于 方法;或者函数;