prototype
直接贴解释了
使用原型来创建对象
在编写构造函数时,可以使用原型对象(它本身是所有构造函数的一个属性)的属性来创建继承属性和共享方法。原型属性和方法将按引用复制给类中的每个对象,因此它们都具有相同的值。可以在一个对象中更改原型属性的值,新的值将覆盖默认值,但仅在该实例中有效。属于这个类的其他对象不受此更改的影响。
直接贴解释了
使用原型来创建对象
在编写构造函数时,可以使用原型对象(它本身是所有构造函数的一个属性)的属性来创建继承属性和共享方法。原型属性和方法将按引用复制给类中的每个对象,因此它们都具有相同的值。可以在一个对象中更改原型属性的值,新的值将覆盖默认值,但仅在该实例中有效。属于这个类的其他对象不受此更改的影响。
解决方案 »
- jquery easyui demo 在vs中运行错误
- 请教js网页需要设置浏览器权限吗?
- 哪一种嵌入网页的播放器可以控制播放的时间点或可以得到播放文件的时间长度
- EXT 动态在items中添加内容
- document.domain能直接进行赋值操作吗?
- Firfox中的firbug看不到JavaScript选项
- 超链接被限制 有突破代码 ???????????????????????????????????
- 3dmax做的东西,能否在网页里显示?能否把3ds文件导为vml文件?
- 那位做过这种东东得帮我个忙啊!!!
- 简单且急用的东西,可我不会,帮忙请进...
- 请教,JS动态文本框取值问题?
- 关于重复调用同一段JAVASCRIPT代码
事件在第一个div上 双击 结果把第2个div关闭了
代码重新贴一下
<style type="text/css">
.ff{ width:300px; height:200px; background:#990000; margin:20px;}
</style>
<script>
function haha(a){
this.parent = document.body
this.id=a
}haha.prototype.create=function(){
var div = document.createElement("div")
div.className = "ff"
div.id=this.id
this.parent.appendChild(div)
this.db()
}haha.prototype.db=function(){
var obj = document.getElementById(this.id)
var me = this
obj.attachEvent("ondblclick",function(){ me.remove()})
}haha.prototype.remove = function(){
document.body.removeChild(document.getElementById(this.id))
}window.onload= function (){
var g = new haha("a")
g.create()
var c = new haha("b")
c.create()
}
</script>
<body>
</body>
.ff{ width:300px; height:200px; background:#990000; margin:20px; color:#fff; font:bold 30px/200px '宋体'; text-align:center;}
</style>
<script>
function haha(a){
this.parent = document.body
this.id=a
}haha.prototype.create=function(){
var div = document.createElement("div")
div.className = "ff";
div.innerHTML = this.id;
div.id=this.id
this.parent.appendChild(div)
this.db()
}haha.prototype.db=function(){
var obj = document.getElementById(this.id)
var me = this
obj.attachEvent("ondblclick",function(){ me.remove()})
}haha.prototype.remove = function(){
document.body.removeChild(document.getElementById(this.id))
}window.onload= function (){
var g = new haha('a')
g.create()
var c = new haha('b')
c.create()
}
</script>
<body>
</body>
后面用的是不同的id了
点第一个div还是先关闭的第2个div
其实对这些机制很不熟悉
<style type="text/css">
.ff{ width:300px; height:200px; background:#990000; margin:20px;}
</style>
<script>
function haha(a){
this.parent = document.body
this.id=a
}haha.prototype.create=function(){
var div = document.createElement("div")
div.innerHTML="<font color=white>"+this.id+"</font>";
div.className = "ff"
div.id=this.id
this.parent.appendChild(div)
this.db()
}haha.prototype.db=function(){
var obj = document.getElementById(this.id)
var me = this
obj.attachEvent("ondblclick",function(){ me.remove()})
}haha.prototype.remove = function(){
document.body.removeChild(document.getElementById(this.id))
}window.onload= function (){
var g = new haha("a")
g.create()
var c = new haha("b")
c.create()
}
</script>
<body>
</body>
点第1个div
结果第2个div先关闭了。。
.ff{ width:300px; height:200px; background:#990000; margin:20px;}
</style>
<script>
function haha(a){
this.parent = document.body
this.id=a
}haha.prototype.create=function(){
var div = document.createElement("div")
div.className = "ff"
div.id=this.id
div.innerHTML=div.id;
this.parent.appendChild(div)
this.db()
}haha.prototype.db=function(){
var obj = document.getElementById(this.id)
var me = this
obj.attachEvent("ondblclick",function(){ me.remove()})
}haha.prototype.remove = function(){
document.body.removeChild(document.getElementById(this.id))
}window.onload= function (){
var g = new haha("a")
g.create()
var c = new haha("b")
c.create()
}
</script>lz点第一个消失后第二个顶上去了
并不是第二个关闭了
我改了下<style type="text/css">
.ff{ width:300px; height:200px; background:#990000; margin:20px;}
</style>
<script>
function haha(a){
this.parent = document.body
this.id=a
}haha.prototype.create=function(){
var div = document.createElement("div")
div.className = "ff"
div.innerHTML = this.id//看看关的是那个
div.id=this.id
this.parent.appendChild(div)
this.db(div)
}haha.prototype.db=function(obj){
var me = this
obj.attachEvent("ondblclick",function(){ me.remove(obj)})
}haha.prototype.remove = function(obj){
document.body.removeChild(obj)
}window.onload= function (){
var g = new haha('a')
g.create()
var c = new haha('b')
c.create()
}
</script>
<body>
</body>
果然是下面的一个div顶上去了