聚焦时清空,失焦时显示默认值
在普通的文本框里可以这样
<!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>
<script language="javascript">
<!--
function cleartxt() {
var value=document.getElementById("txt").value;
if(value=="在这里搜索") //聚焦时,如果文本框为初始值,则清空
document.getElementById("txt").value="";
}
function resettxt() {
var value=document.getElementById("txt").value;
if(value==""||value==null) //失焦时,如果文本框为空,则给初始值
document.getElementById("txt").value="在这里搜索";
}
function computer() {
document.write(document.getElementById("txt").value); //获取提交值
}
//-->
</script>
</head>
<body>
<form id="myform">
<input type="text" id="txt" value="在这里搜索" onfocus="cleartxt()" onblur="resettxt()" />
<input type="button" id="btn" value="搜索" onclick="computer()" />
</form>
</body>
</html>在ASP.NET服务器控件中
<td><asp:TextBox ID="TextBox1" runat="server" BorderStyle="Double" Width="223px" ForeColor="DimGray" value="在这里搜索" onfocus="cleartxt()" onblur="resettxt()" ></asp:TextBox></td>
<td><asp:Button ID="Button1" runat="server" Text="搜索" OnClick="Button1_Click" BackColor="#404040" BorderColor="DimGray" BorderStyle="Solid" ForeColor="White" Height="22px" Width="73px" />
获取不到TextBox的id,怎样做
在普通的文本框里可以这样
<!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>
<script language="javascript">
<!--
function cleartxt() {
var value=document.getElementById("txt").value;
if(value=="在这里搜索") //聚焦时,如果文本框为初始值,则清空
document.getElementById("txt").value="";
}
function resettxt() {
var value=document.getElementById("txt").value;
if(value==""||value==null) //失焦时,如果文本框为空,则给初始值
document.getElementById("txt").value="在这里搜索";
}
function computer() {
document.write(document.getElementById("txt").value); //获取提交值
}
//-->
</script>
</head>
<body>
<form id="myform">
<input type="text" id="txt" value="在这里搜索" onfocus="cleartxt()" onblur="resettxt()" />
<input type="button" id="btn" value="搜索" onclick="computer()" />
</form>
</body>
</html>在ASP.NET服务器控件中
<td><asp:TextBox ID="TextBox1" runat="server" BorderStyle="Double" Width="223px" ForeColor="DimGray" value="在这里搜索" onfocus="cleartxt()" onblur="resettxt()" ></asp:TextBox></td>
<td><asp:Button ID="Button1" runat="server" Text="搜索" OnClick="Button1_Click" BackColor="#404040" BorderColor="DimGray" BorderStyle="Solid" ForeColor="White" Height="22px" Width="73px" />
获取不到TextBox的id,怎样做
解决方案 »
- 关于字符串比较的问题,求大神帮忙!
- 有动态修改*.aspx或*.master文件的经验的朋友请进!
- Cache.Add 与Cache.Insert 的区别
- 如何用js提交页面也能执行Button事件?
- 紧急问题,希望各位大大帮忙解决。
- 问个问题.ASP.NET是传值还是传指针
- 关于流量统计的问题
- 关于数据验证控件的问题!!请高手帮帮忙!!
- 求js提取文字拼音的首字母?js中如何调用c#的方法,并传递参数?
- DataBinder.Eval(Container.DataItem, "ControllWeb")的含义
- 请教百度快照不更新,不收录和网站日志的问题
- 前台拖入label控件,后台似乎找不到这个控件
修改为
var value=document.getElementById('<%=TextBox1.ClientID%>').value;就可以了
他又没用repeater或者gridview等控件,干嘛要这样写。直接TextBox1就行了么。
感谢了
我是在客户端调用js