PicList.prototype.run = function(){ log(this.elem) //null } 这句获取了空值...哪里出错了?
function log(i){ return console.log(i); } function $ (id)
{
if(typeof id === "string"){
return document.getElementById(id);
}else{
return id;
}
}
function PicList(){
this.elem = $(arguments[0]);
this.arr = [];
var iTarget = [
{ left:0 },
{ left:50 },
{ left:100 },
{ left:150 },
{ left:200 }
];
this.run();
}
PicList.prototype.run = function(){
log(this.elem) //null
}
Animate.prototype = new PicList("wrap");
function Animate(){
log(this.arr)
}
var obj = new Animate();
//HTML
<div id="wrap"> </div>
function log(i){ return console.log(i); } function $ (id)
{
if(typeof id === "string"){
return document.getElementById(id);
}else{
return id;
}
}
function PicList(){
this.elem = $(arguments[0]);
this.arr = [];
var iTarget = [
{ left:0 },
{ left:50 },
{ left:100 },
{ left:150 },
{ left:200 }
];
this.run();
}
PicList.prototype.run = function(){
log(this.elem) //null
}
Animate.prototype = new PicList("wrap");
function Animate(){
log(this.arr)
}
var obj = new Animate();
//HTML
<div id="wrap"> </div>
解决方案 »
- datagrid无法显示数据
- js 为什么我获取不到options选项里label的值。怎么样改才能获取到,请在源码上修改。
- easyui combotree如何实现级联
- html的checkbox在ie与ff中的差异
- javascript 的语法好像很混乱 ,函数传参到底有多少种方法
- 鼠标离开时候换另外一张图的js代码?
- 谁有AJAX或JS的文字直播代码
- 取得<select><option>yyyyyyyy</option></select>中的<option></option>中间的值的方法是什么?
- 如何清空table 指定行中 所有textbox 的value 值
- JS 字符串变量 怎么才能够包含JS代码 急求
- 都说字符串优化的方式是join
- 用js处理一段url
function log(i){ return console.log(i); } function $ (id)
{
if(typeof id === "string"){
return document.getElementById(id);
}else{
return id;
}
}
function PicList(){
this.elem = $(arguments[0]);
alert(this.elem.id);
this.arr = [];
var iTarget = [
{ left:0 },
{ left:50 },
{ left:100 },
{ left:150 },
{ left:200 }
];
this.run();
}
PicList.prototype.run = function(){
log(this.elem) //null
}
</script></head><body>
<div id="wrap"> </div>
<script type="text/javascript">
Animate.prototype = new PicList("wrap");
function Animate(){
log(this.arr)
}
var obj = new Animate();
</script>
这样试试 貌似是因为Animate.prototype = new PicList("wrap");时你的那个div还没加载进来,所以为null
我也是猜的 js继承那块没好好看
<div id="wrap"> </div>
<script>
function log(i){ return console.log(i); } function $ (id)
{
if(typeof id === "string"){
return document.getElementById(id);
}else{
return id;
}
}
function PicList(){
this.elem = $(arguments[0]);
this.arr = [];
var iTarget = [
{ left:0 },
{ left:50 },
{ left:100 },
{ left:150 },
{ left:200 }
];
this.run();
}
PicList.prototype.run = function(){
log(this.elem) //null
}
Animate.prototype = new PicList("wrap");
function Animate(){
log(this.arr)
}
var obj = new Animate();
</script>