2014年10月23日 星期四

在沒有placeholder的時候,TEXT的提示字

就如題,現在HTML5,TEXT裡有placeholder可以用

以前沒有這功能時,用JavaScript實現

<input type="text" name="search" id="search" value="" onfocus="onfocusState()" onblur="onfocusState()"/>
     
function onfocusState() {
    if (document.getElementById("search").value == "請輸入關鍵字....") {
        document.getElementById("search").value = "";
    } else if (document.getElementById("search").value == "") {
        document.getElementById("search").value = "請輸入關鍵字....";
    } else { }
}

沒有留言:

張貼留言