为IE添加placeholder支持功能,采用悬浮的span元素方式来模拟placeHolder,一般的,你在不输入的时候,会取到框内的值。此方法就没有这个担忧了。
<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>placeholder支持IE6/7</title>
<script type="text/javascript" src="jquery.1.9.1.min.js"></script>
<script type="text/javascript" src="jquery.placeholder1.0.js"></script>
<script type="text/javascript">
$(function(){
$('input').placeholder({isUseSpan:true});
})
function getValue() {
var textValue = $("#userName").val();
alert(textValue);
}
</script>
</head>
<body>
<form>
<label for="name">用户名</label>
<input type="text" id="userName" placeholder="输入用户名"/>
<input type="button" value="取值" οnclick="getValue()"/>
</form>
</body>
</html>
下面有两个js控件,加入即可