当文本框获取焦点时,改变背景色(可在样式表中引用:input,textarea { behavior:url(/css/***.htc); })
Posted on 2011-03-10 16:18 X龙 阅读(1444) 评论(0) 编辑 收藏 举报<!--
/*==================================/
*与样式textBox绑定的行为文件
*
*功能:
* 实现当用户的光标定位在某输入框时,
* 该输入框显示不同的颜色的动态效果
===================================*/
-->
<public:attach event="onfocus" onevent="doFocus()"/>
<public:attach event="onblur" onevent="doBlur()"/>
<script language="jscript">
function doFocus()
{
if(element.tagName != 'INPUT' && element.tagName != 'TEXTAREA')
return false;
if(element.tagName == 'INPUT' && (element.type == "submit" || element.type == "button" ))
return false;
if(!element.readOnly)
{
element.style.backgroundColor = '#E0FFFF';
}
}
function doBlur()
{
if(element.tagName != 'INPUT' && element.tagName != 'TEXTAREA')
return false;
if(element.tagName == 'INPUT' && (element.type == "submit" || element.type == "button" ))
return false;
element.style.backgroundColor = '#FFFFFF';
}
//取cookie的内容
function getCookieVal (offset)
{
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
//获取指定cookie的值
function getCookie (name)
{
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen)
{
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
</script>
/*==================================/
*与样式textBox绑定的行为文件
*
*功能:
* 实现当用户的光标定位在某输入框时,
* 该输入框显示不同的颜色的动态效果
===================================*/
-->
<public:attach event="onfocus" onevent="doFocus()"/>
<public:attach event="onblur" onevent="doBlur()"/>
<script language="jscript">
function doFocus()
{
if(element.tagName != 'INPUT' && element.tagName != 'TEXTAREA')
return false;
if(element.tagName == 'INPUT' && (element.type == "submit" || element.type == "button" ))
return false;
if(!element.readOnly)
{
element.style.backgroundColor = '#E0FFFF';
}
}
function doBlur()
{
if(element.tagName != 'INPUT' && element.tagName != 'TEXTAREA')
return false;
if(element.tagName == 'INPUT' && (element.type == "submit" || element.type == "button" ))
return false;
element.style.backgroundColor = '#FFFFFF';
}
//取cookie的内容
function getCookieVal (offset)
{
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
//获取指定cookie的值
function getCookie (name)
{
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen)
{
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
</script>