/*設置input 焦點*/ $(function () { //集體調用 $(".formTextBoxes input").each(function () { $(this).setDefauleValue(); }); //單個調用 $(".textkey").setDefauleValue(); }) //設置input,textarea默認值 .之前寫法$.fn.seDefauleValue = function(){ $.fn.setDefauleValue = function () { var defauleValue = $(this).val(); $(this).val(defauleValue).css("color", "#999"); return this.each(function () { $(this).focus(function () { if ($(this).val() == defauleValue) { $(this).val("").css("color", "#000"); //輸入值的顏色 } }).blur(function () { if ($(this).val() == "") { $(this).val(defauleValue).css("color", "#999"); //默認值的顏色 } }); }); }
Html:
<div class="formBoxes formTextBoxes clearfix"> <input id="txtSearch" type="text" value='@ViewBag.SearchText' class="searchMainBtn easyui-validatebox" /> <div id="btnSearch" class="btnGo" >@ViewBag.Search</div> </div>