HTML Code
1 2 3 4 5 | < form id = "form1" name = "form1" method = "post" action = "" > คำค้น < input name = "mykeyword" type = "text" id = "mykeyword" size = "50" /> < input type = "submit" name = "Submit" value = "ค้นหา" /> </ form > |
Javascript Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | <script language= "javascript" src= "js/jquery-1.2.6.min.js" ></script> <script type= "text/javascript" > $( function (){ var objSet= "#mykeyword" ; var objSetText= "พิมพ์ข้อความที่นี่" ; if ($(objSet).val()== "" ){ $(objSet).val(objSetText); } $(objSet).focus( function (){ if ($(objSet).val()==objSetText){ $(objSet).val( "" ); } }).blur( function (){ if ($(objSet).val()== "" ){ $(objSet).val(objSetText); } }); }); </script> |
ตัวอย่าง