菜鸟求助! javascript 能否 给html文档中的html 元素 添加 继承? 就象 String.prototype ? 偶知道 用js 动态创建的 html 元素 可以实现 ,但不知道 直接写在 html文件 里的 元素标签 如何实现!` 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 元素只能添加属性吧? 用setAttribute 写了例子,在继承方面没弄明白$D.fn.expent,怎么弄?期待高手详解<input type="text" id="aa"><input type="button" value="hide me" onclick="$D(this).hide()"><script>(function(){ var $D =window.$D = function(_id){ return new $D.fn.init(_id); }; $D.fn=$D.prototype={ element:null, init:function(_id) { if(typeof _id=="string") { this.element = document.getElementById(_id); }else if(typeof _id=="object") { this.element = _id; } return this; }, hide:function(){this.element.style.display="none";}, show:function(){this.element.style.display="block";} } $D.fn.init.prototype = $D.fn;})();$D("aa").hide();</script> $D.fn.extend({ check:function(){return 1;} });不知道这里用extend怎么不行alert($D("aa").check()); 不知道楼主是不是这个意思。例如:让所有的htmlElement都有all方法直接将下面一段放入页面<script>if(window.HTMLElement){ HTMLElement.prototype.__defineGetter__("all",function(){ var a=this.getElementsByTagName("*"); var node=this; a.tags=function(sTagName){ return node.getElementsByTagName(sTagName); } return a; }); }</script> window.HTMLElement 为 false ....我IE7 你怎么写的?? window.HTMLElement跟什么浏览器没有关系吧?是HTMLElement元素就是true,不是当然就是false了 原型链的2个小问题 同一个页面第二个jQuery的function()为什么不起作用 太神奇了,JS删除后还能起作用 继续求教JQuery 关于XMLHTTP的问题,请帮我看一下 框架页面左右联动刷新问题 web打印搞定了,大家共享吧 二十万火急,我忘了是哪个元素可以实现以下功能了,只用html 打开主页,怎样以跳转覆盖主页的形式打开我的FLASH(.swf)页面 请问如何用Window.open()把新建窗口的Title去掉,好象Title=0的属性不管用? 保存效果 关于不同页面调用js方法问题
<input type="button" value="hide me" onclick="$D(this).hide()"><script>
(function(){
var $D =window.$D = function(_id){
return new $D.fn.init(_id);
};
$D.fn=$D.prototype={
element:null,
init:function(_id)
{
if(typeof _id=="string")
{
this.element = document.getElementById(_id);
}else if(typeof _id=="object")
{
this.element = _id;
}
return this;
},
hide:function(){this.element.style.display="none";},
show:function(){this.element.style.display="block";}
}
$D.fn.init.prototype = $D.fn;})();$D("aa").hide();</script>
check:function(){return 1;}
});
不知道这里用extend怎么不行
alert($D("aa").check());
<script>
if(window.HTMLElement){
HTMLElement.prototype.__defineGetter__("all",function(){
var a=this.getElementsByTagName("*");
var node=this;
a.tags=function(sTagName){
return node.getElementsByTagName(sTagName);
}
return a;
});
}
</script>
我IE7