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",:οnfοcus=>'clearText(this)', :style=>'color:#ccc;', :οnblur=>'refill(this)'} %>