我有一个文本框 默认值是  "编号道路小区"  有2个事件,获得焦点时清空 文本,失去焦点时还原默认值,  还有一个搜索按钮,
    我想点击搜索按钮 让 文本框的失去焦点失效    ,在点击页面让 失去焦点还原
   怎么做啊....??

解决方案 »

  1.   

    function clearDefaultText (el,message)
    {
        var obj = el;
        if(typeof(el) == "string")
        obj = document.getElementById(id);
        if(message == "")
        {
            message = "最近心情怎么样?不妨写下心情短语吧...";
        }
            if(obj.value == message)
                {
                    obj.value = "";
                }
            obj.onblur = function()
            {
                if(obj.value == "")
                {
                    obj.value = message;
                }
            }
    }
      

  2.   

    <input name="keyWord" type="text" id="keyWord" value="关键字" size="8" onblur="if (this.value =='') this.value='关键字'" onmouseover="this.focus()" onfocus="this.select()" onclick="if (this.value=='关键字') this.value=''" />