js技术分享

什么是失去焦点javascript

JSP表单元素获取焦点就是指你的text,password等元素里有鼠标的光标. 同理 JSP失去焦点例如浏览器上方标题是蓝色的时候 就证实焦点就在这里 当你点其余页面的时候它会变灰.就是失去焦点.原理都同样.css

演示代码html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> java

<html xmlns="http://www.w3.org/1999/xhtml"> 浏览器

<head> post

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> ui

<title>边框变色</title> orm

<style type="text/css"> xml

<!-- htm

.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>

什么是获取焦点

用自带的focus();就能够了;下面是小例子: var oTxt = document.getElementById('txt').focus();

 

js 设置焦点 判断控件是否得到焦点 判断哪一个控件得到焦点

设置焦点

判断控件是否得到焦点

if(document.activeElement.id="txtIdHouse")

{

}

判断哪一个控件得到焦点

var act = document.activeElement.id;

act就是如今得到焦点控件的id值

分类: HTML&JavaScript

相关文章
相关标签/搜索