/直接基于jQuery的扩展,判断是否为空
$.isBlank =
function
(obj){
return
(
typeof
(obj)==
‘undefined‘
||obj==
‘‘
||obj==
null
);
}
//直接基于jQuery的扩展,去除html标签,保留内容
$.htmlContent =
function
(tag){
var
reTag = /<(?:.|\s)*?>/g;
return
tag.replace(reTag,
""
);
}
//直接基于jQuery的扩展(方式二)
$.xy = {
sayhello:
function
(){
return
"hello"
;},
saybaybay:
function
(){
return
"baybay"
;}
};
//jQuery类级别的扩展
$.extend({
add:
function
(a,b){
return
a+b;},
diff:
function
(a,b){
return
a-b}
});
//jQuery对象级别的扩展
$.fn.extend({
getvalue:
function
(){
return
this
.val();
}
});
html代码
<
body
>
<
script
type
=
"text/javascript"
>
document.write("判断是否为空:"+$.isBlank(null));
</
script
>
<
span
class
=
"myspan"
></
span
>
<
script
type
=
"text/javascript"
>
document.write("过滤html标签:"+$.htmlContent("<
html
><
body
><
a
id
=
‘a1‘
>a标签</
a
><
div
style
=
‘width:100%‘
>div标签</
div
>内容</
body
></
html
>")+"<
br
/>");
document.write("扩展自jQuery类的xy的sayhello方法:"+ $.xy.sayhello()+"</
br
>");
document.write("扩展自jQuery类的xy的sayhello方法:"+ $.xy.saybaybay()+"</
br
>");
document.write("基于jQuery类的add法:"+ $.add(3,5)+"</
br
>");
document.write("基于jQuery类的diff法:"+ $.diff(5,3)+"</
br
>");
document.write("基于自jQuery类对象的扩展getvalue():"+$("<
input
type
=
‘text‘
value
=
‘str‘
/>").getvalue()+"<
br
/>");
</
script
>
</
body
>