当前位置:编程学习 > JS >>

让输入框得到焦点并选中变色的效果

让输入框度变色,一个比较实用的美化实例,鼠标点击文本框,获得输入框焦点,并改变输入框的边框颜色,意在区分其它输入框,其实只用CSS就可以很好的实现。
答案:<!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>
<style type="text/css">
<!--
.SearchKeyword {border:1px solid #797A75;width: 202px;color: #CDCDCD;font-size:12px;}
.SearchKeywordonFocus {border:1px solid #ABCD3A;width: 202px;color: #000000;font-size:12px;}
-->
</style>
<script language="javascript">
function keywordfocus()
{
if (document.formSearch.keyword.value == '请输入关键字')
{
document.formSearch.keyword.value = '';
document.formSearch.keyword.className = 'SearchKeywordonFocus';
}
}
function keywordblur()
{
if (document.formSearch.keyword.value == '')
{
document.formSearch.keyword.value = '请输入关键字';
document.formSearch.keyword.className = 'SearchKeyword';
}
}
</SCRIPT>
</head>
<body>
<form id="formSearch" name="formSearch" method="post" action="">
<input type="text" name="keyword"  class="SearchKeyword" value="请输入关键字" onFocus="keywordfocus();" onBlur="keywordblur();"  />
</form>
</body>
</html>

上一个:你见过这种按钮套按钮的按钮吗?
下一个:JavaScript密码强度检测代码

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,