获得焦点时,文本框内值隐藏,失去焦点时,文本框内的值显示

javascript代码:
function clearText(thefield){
if (Element.readAttribute(thefield, "defaultvalue")==thefield.value){
thefield.value = ""
thefield.style.color="black"
}
}

function refill(thefield){
if(thefield.value==""){
thefield.value=Element.readAttribute(thefield, "defaultvalue")
thefield.style.color="#ccc"
}
}

ruby代码:

<label for="search_query">Search</label>
<%= text_field_tag 'q', "Search", {:id=>"search_query", :class=>"text_field", :defaultValue=>"Search",:onfocus=>'clearText(this)', :style=>'color:#ccc;', :onblur=>'refill(this)'} %>



你可能感兴趣的:(JavaScript,Ruby)