<body>
<script>
var d = null;
function create(elm,parent,fn,o){
o = document.createElement(elm);
fn&&fn(o);
parent&&parent.appendChild(o);
return o
};
create('div',null,function(elm){elm.id='ss'},d)
alert(d); //d还是null 我以为是obj了
</script>
</body>
<script>
var d = null;
function create(elm,parent,fn,o){
o = document.createElement(elm);
fn&&fn(o);
parent&&parent.appendChild(o);
return o
};
create('div',null,function(elm){elm.id='ss'},d)
alert(d); //d还是null 我以为是obj了
</script>
</body>
解决方案 »
- 做网页游戏。现在用js 的话。后台不考试。那前端用什么组合最好?
- 为什么这个sql插不进去呀???(在线等)
- 第一打开网页时右下角有错误提示,刷新一下就没了,是什么原因?
- 高分求助js问题
- onclick设置内容之后,为何typeof(onclick)的值从object变为function?试验代码见正文
- iframe问题(急)
- 什么是javascript的防错处理
- frame中如何让左边窗口事件发生时,刷新右边窗口页面呀???要命
- 连接和onclick 中的submit同时进行,该如何操作???!!!
- 怎样把 001,002, 字符(两组数、两个逗号)转换为stu_id in ('001','002')
- 救急啊,高手一下解决的问题,我搞了半天还没出来.
- 各位大哥救命啊~!!在线等答案!~~~
你d=null
然后给null赋值当然没用了啊
相当于
null = 2
看错了<script>
var d = null ;
function create(elm,parent,fn,o){
o = document.createElement(elm);
fn&&fn(o);
parent&&parent.appendChild(o);
return o
};
d = create('div',null,function(elm){elm.id='ss'},d)
alert(d);
</script>
<body>
<script>
var d =1;
function create(o){
o = 2;
return o
};
create(d)
alert(d); //d输出还是1
</script>
</body>
不过确切的说变量o是变量d的引用,除非直接对这个引用操作,才会改变d的值,
例子:var a=[]; (function(o){o.push(2);})(a); alert(a);
如果改变o的引用(如赋值),o的作用域只在create