hi, 有很多地方的textbox,我们可以看到里面是有些灰色的默认字的,请问这个怎么实现呢?
再进一步,里面还有些提示文字,而我不希望用户更改他们,而且希望用户的输入在这些提示之后,就像前面的部分是不能选择一样,可以实现么?
比如:【】这个是textbox
显示出来是这样: 【提示:灰色默认字】
当用户将鼠标点击到这个textbox时,变成这样: 【提示: 】, 光标出现在“提示:”之后。
谢谢!
------解决方案--------------------------------------------------------
JS 控制的 获取焦点 失去焦点事件
------解决方案--------------------------------------------------------
给你一段代码示例你可以看看
- JScript code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>无标题文档</title><script>function check(){ if(document.form1.name.value=="可以输入学号姓名进行搜索") { document.form1.name.value =""; document.form1.name.focus(); document.getElementsByTagName("input")[0].style.color="red"; }}function chesk(){ if(document.form1.name.value=="") { document.getElementsByTagName("input")[0].style.color="#cccccc"; document.form1.name.value="可以输入学号姓名进行搜索" }}</script><style>.show{border:1px solid red;color:#999999; width:200px;}</style></head><body><form name ="form1"><label><input type="text" name="name" class="show" value="可以输入学号姓名进行搜索" onmousemove="check()" onmouseout="chesk()" /></label></form></body></html>