input内容变更以及透明度小插件
很多网站的搜索输入框会显示一个“搜索。。”这样的文本, 当我们移入鼠标之后会被清空让我们输入东西。 这里把实现该功能的代码写成插件形式。代码如下: [code="js"](function($){ $.fn.myInput=function(opts){ var setting=$.extend({ opacity:0.5, content:"Search.." },opts||{}); if($(this).val()!=setting.content){ //alert("input的初始值必须与参数值一致, 参数默认值为'Search..'"); $(this).val(setting.content); } $(this).css("opacity",setting.opacity); $(this).focus(function(){ // $(this).css("border","none"); $(this).css("opacity",1); if($(this).val()==""||$(this).val()==setting.content){ $(this).val(""); } }); $(this).focusout(function(){ if($(this).val()==""){ $(this).val(setting.content); $(this).css("opacity",setting.opacity); } }); } })(jQuery);[/code] demo.html: [code="html"] [/code]