jQuery插件
;(function($)
{
$.fn.mchoice=function(target)
{
var $target=$(target);
var $this=this;
$(":checkbox",$this).on("click",function()
{
if($(this).is(":checked"))
{
var html=$('<span style="background-color:#ccc;display:inline-block;padding:2px 7px;line-height:14px;margin-bottom:2px;font-size:12px;margin-right:5px;">'+$(this).val()+'</span>');
$target.prepend(html);
}else
{
$("span:contains("+$(this).val()+")",$target).remove();
}
})
}
})(jQuery);//封装插件
$(".hyfx").mchoice("#_p");//调用插件
;(function($){
$.fn.extend({
"color":function(value){
if (value ==undefined){
return this.css("color");
} else {
return this.css("color",value);
}
}
});
})(jQuery);
此时,color()插件的功能已经全部实现了,通过该插件可以获取和设置元素的color值。实际上,css()方法内部已经有判断value是否为undefined的机制,所以才可以根据传递参数的不同而返回不同的值,因此,可以借助css()方法的这个特性来处理这个问题。删除if()部分,最终剩余的代码实际上与先前的那段一模一样。代码如下:
;(function($){
$.fn.extend({
"color":function(value){
return this.css("color",value);
}
});
})(jQuery);
如何编写一个Jquery插件
http://www.skygq.com/2010/12/07/how-to-write-a-jquery-plugin/
$(".nav li:first").css('border','0')
$('.nav li').eq(0).css('border','0')
测试:alert($('li').eq(6).html())
$('#back-Top').click(function(){$('html,body').animate({scrollTop: '0px'}, 800);return false;});
<script>
window.onscroll=function(){
function Fixed(obj, top){
var scrollTop = document.body.scrollTop || document.documentElement.scrollTop; //document.documentElement.scrollTop是IE的,获取可视区与文档顶部距离 document.body.scrollTop是Webkit定位
obj.style.top = top + scrollTop + 'px';
}
var a=document.getElementById('fixed');
Fixed(a,200);
}
</script>
window.onload = window.onscroll = function(){
var oDiv = document.getElementById("fixed");
var a = document.getElementById("top");
var top = oDiv.offsetTop;
Fixed(oDiv, 200);
Fixed(a,400);
}
function Fixed(obj, top){
var scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
var t = top + scrollTop
MOVE:Buffer_Move(obj, {top: t});
}
$('.box").each(function(){
var h = $(this).height();
$(this).wrapInner('<div sytle="height:' + h +';"></div>'); //box包裹一个div
}
$('.box").each(function(){
var h = $(this).height();
var w = $(this).width();
var $inner=$('<div></div>').height(h-2).width(w-2)
$(this).wrapInner($inner);
$(this).wrapInner($inner[0]);//上面那行不行用这行试试
}
var $inner=$('<div></div>').height(h-2).width(w-2)可以改为
var $inner=$('<div></div>')
$inner.css({
"height":h-2,
"width": w-2,
"margin-top":1,
"margin-left":1
});
//根据子框架高度重新设置父框架高度
$('#MainFrame',window.parent.document).height($("body").height());

浙公网安备 33010602011771号