如题:有一个input;<input type="text" value="默认"/>
当未选中input时,input显示默认值“默认”,并且颜色为灰色,当选中input后,删除默认值"默认",并且在此输入文字后,颜色为黑色。
当未选中input时,input显示默认值“默认”,并且颜色为灰色,当选中input后,删除默认值"默认",并且在此输入文字后,颜色为黑色。
解决方案 »
- 正则表达式|的奇怪问题!!
- Jquery多条件筛选的问题
- 怎么样检查点击是否在一个表格里面
- 帮忙看看这个javascript效果是怎么做出来的?效果叫什么名字?????????????
- js关闭电脑
- javascript函数的一个传值问题,同样的数据,得到不同的结果
- Tab 菜单导航 js 刷新传值问题 急候高手相助!!!
- 层数据设置修改问题
- 大家帮忙看看我左边导航的上下尖头为什么不管用?
- 没人回答的问题,关于htc的对事件的响应
- ckeditor 自己添加了事件,然后 setData("值") 操作后事件失效,再次绑定也不成功???谁有好的解决方法,急!急!急!急!急!急!急!急!
- 关于jsp实现搜索的功能, 可以帮下忙么,
<!doctype html>
<html>
<head>
<meta charset="gb2312" />
<style>
</style>
</head>
<body>
<input id="test" type="text" value="默认" style="color:#999;" />
<script>
function $(o){return document.getElementById(o)}
$('test').onfocus = function(){
if( this.value == this.defaultValue ){
this.value = '';
this.style.color = '#000';
}
}
</script>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
window.onload = function() {
document.getElementById('demo').onclick = function() {
var obj = this.getElementsByTagName('input')[0];
obj.value = '';
obj.disabled = false;
obj.focus();
}
}
</script>
</head><body>
<span id="demo"><input type="text" value="默认" disabled="disabled" /></span>
</body>
</html>
又添加了 失焦的<!doctype html>
<html>
<head>
<meta charset="gb2312" />
<style>
</style>
</head>
<body>
<input id="test" type="text" value="默认" style="color:#999;" />
<script>
function $(o){return document.getElementById(o)}
$('test').onfocus = function(){
if( this.value == this.defaultValue ){
this.value = '';
this.style.color = '#000';
}
}
$('test').onblur = function(){
if( this.value == '' || this.value == this.defaultValue ){
this.value = this.defaultValue;
this.style.color = '#999';
}
}
</script>
</body>
</html>直接copy代码 另存为 ××.html 双击就可以了.
?