<html>
<head>
<title>实现文本框获得焦点,文本框里提示信息自动消失 </title>
<link href="css/StyleSheet1.css" rel="stylesheet" type="text/css" />
<script src="js/jquery-1.4.2.min.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function () {
$('#txtArea').focus(function () {
with (event.srcElement)
//如果当前值为默认值,则清空
if (value == defaultValue) value = ""
});
$('#txtArea').blur(function () {
with (event.srcElement)
if (value == "") value = defaultValue
});
});
</script>
</head>
<body>
<textarea id="txtArea" class="txtcss" runat="server" value="填写问题"></textarea>
</body>
</html>
<head>
<title>实现文本框获得焦点,文本框里提示信息自动消失 </title>
<link href="css/StyleSheet1.css" rel="stylesheet" type="text/css" />
<script src="js/jquery-1.4.2.min.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function () {
$('#txtArea').focus(function () {
with (event.srcElement)
//如果当前值为默认值,则清空
if (value == defaultValue) value = ""
});
$('#txtArea').blur(function () {
with (event.srcElement)
if (value == "") value = defaultValue
});
});
</script>
</head>
<body>
<textarea id="txtArea" class="txtcss" runat="server" value="填写问题"></textarea>
</body>
</html>
本文介绍了一种使用jQuery实现的文本框焦点切换效果,当文本框获得焦点时,若其内容为默认提示信息则自动清除;当文本框失去焦点且为空时,自动恢复默认提示信息。
610

被折叠的 条评论
为什么被折叠?



