25分求助,怎样在TextBox添加"请你输入要搜索的信息".鼠标移到TextBox后,内容变没了.
25分求助,怎样在TextBox添加"请你输入要搜索的信息".鼠标移到TextBox后,内容变没了. --------------------编程问答-------------------- ...给onmouseover写javascript --------------------编程问答-------------------- 默认情况下,设置文本CSS,然后JAVASCRIPT在ONMOUTHOVER或KEYPRESS事件中动态改变文本内容和样式。 --------------------编程问答-------------------- 在TextBox的属性text中写“请你输入要搜索的信息”;在TextBox的onmousemove事件调用以下事件
function disTexboxInfo()
{
document.getElementById("TextBox").value="";
}
在TextBox的onmousedown事件调用以下事件
function TexboxInfo()
{
document.getElementById("TextBox").value="请你输入要搜索的信息";
}
--------------------编程问答-------------------- <input type="text" id="" value="aaaaaaaa" onmouseover="if (this.value=='aaaaaaaa'){this.value='';this.select();}" onmouseout="if (this.value==''){this.value='aaaaaaaa';this.blur();}" /> --------------------编程问答-------------------- textbox1.Attribute.Add("onmouseout","Javascript:document.Form1.文本框.value=''"); --------------------编程问答-------------------- 看上去有5条回复,结果打开后,什么都没有看到,是不是有bug啊。 --------------------编程问答-------------------- <script language="javascript">
function aa(txtsearch)
{
txtsearch.value="";
}
</script>
输入关键字:<asp:TextBox ID="txtsearch" runat="server" Width="180px" onfocus="aa(txtsearch)" Text="请输入关键字!!"></asp:TextBox> --------------------编程问答-------------------- JavaScript 实现:
TextBox1.attribute.Add("onfocus","onmove()");
这里的onmove()是javascript的方法,设置文本框的值为“” 就行了! --------------------编程问答-------------------- 直接用Ajax控件 --------------------编程问答-------------------- 服务器控件有个客户端脚本属性
client
掉一个函数改变值就可以了 --------------------编程问答-------------------- lishijie910123你的方法可以实现,但提示有语法错误。
Line:17
Char:19
Code:0
Error:缺少 ';'
不明白。
--------------------编程问答-------------------- 找JS就行了,直接看有这个效果的网站的代码就知道了,最简单的办法需要onblur()方法 --------------------编程问答-------------------- 下面这个例子,TextBox的Text初始值为“--请你输入要搜索的信息--”
1、当Mouse移到上面,获取焦点,Text值清空。
2、如果没有填写值,失去焦点时,恢复默认的提示信息“--请你输入要搜索的信息--”
3、如果填写了值,那么Text就是你填写的值
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default4.aspx.cs" Inherits="Default4" %>--------------------编程问答-------------------- --------------------编程问答--------------------
<!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 runat="server">
<title>无标题页</title>
<script type="text/javascript" language="javascript">
function OnControlFocus(el)
{
if(el.value == "--请你输入要搜索的信息--")
el.value = "";
el.select();
}
function OnControlBlur(el)
{
if(el.value == "")
el.value = "--请你输入要搜索的信息--";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" Text="--请你输入要搜索的信息--" onmouseover="OnControlFocus(this)" onblur="OnControlBlur(this)" runat="server"></asp:TextBox>
</div>
</form>
</body>
</html>
<script type="text/javascript">
//當關鍵字文框獲取焦點時清空文本框內容
function clearKeyWord()
{
document.all.txtKeyWord.value="";
}
//當關鍵字文本框失去焦點時設置文本框的內容
function setKeyWord()
{
if(document.all.txtKeyWord.value=="")
{
document.all.txtKeyWord.value="......";
}
}
</script>
--------------------编程问答-------------------- Ajax:
<input id="txtKeyWord" onblur="setKeyWord()" onfocus="clearKeyWord()" />
http://www.asp.net/AJAX/AjaxControlToolkit/Samples/TextBoxWatermark/TextBoxWatermark.aspx --------------------编程问答-------------------- <input id="txtKeyWord" value="请你输入要搜索的信息" onfocus="this.value=''" />
--------------------编程问答-------------------- <asp:TextBox TextMode="MultiLine" runat="server" Width="100%" name="NoHtmlCommentContent" id="NoHtmlCommentContent" rows="8" cols="80" onFocus="if(this.value=='字数上限为2000字'){this.value='';}this.select();">字数上限为2000字</asp:TextBox> --------------------编程问答-------------------- <input id="txtKeyWord" value="请你输入要搜索的信息" onfocus="this.value=''" />
--------------------编程问答-------------------- --------------------编程问答--------------------
不错的方法 --------------------编程问答-------------------- <script language="JavaScript">
var clickCount = 0;
function clearCommentContent(oObject) {
clickCount++;
if (clickCount == 1) {
oObject.value = "";
}
}
function EnterRedirect(Obj)
{
if(event.keyCode==13)
Obj.click();
}
</script>
<INPUT id="gongyingguanjianchi" onclick="clearCommentContent(this)" type="text" value="关键词"
name="textfield3" runat="server" onkeydown="EnterRedirect(Submit)"> --------------------编程问答-------------------- 谢谢上面的楼主提供QQ群平台让我们相互流浪、想到学习! --------------------编程问答-------------------- 在c#.Net 中代码如下:
初始textBox1的Text值为:"--请输入信息--"
private void textBox1_Enter(object sender, EventArgs e)
{
textBox1.Clear();
textBox1.Focus();
}
private void textBox1_Leave(object sender, EventArgs e)
{
if (textBox1.Text == string.Empty)
{
textBox1.Text = "--请输入信息--";
}
} --------------------编程问答-------------------- 用不着ajax。
看我写的这段吧。
http://hi.baidu.com/guoscript/blog/item/4fc480fbbfd6af126d22ebb8.html
<script language="javascript">
function blank()
{
if(document.form1.name.value == "Insert ur name")
{
document.form1.name.value = "";
}
}
function back()
{
if(isBlank(""+document.form1.name.value))
{
document.form1.name.value = "Insert ur name"
}
}
function isBlank(s)
{
var len = s.length
var i
for(i=0;i<len;i++)
{
if(s.charAt(i) != " ")
return false
}
return true
}
</script>
<body>--------------------编程问答-------------------- 不就一个JS代码问题么 --------------------编程问答-------------------- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default4.aspx.cs" Inherits="Default4" %>
<form id="form1" name="form1" method="post" action="">
<input name="name" type="text" id="name" onfocus="blank()" onblur="back()" value="Insert ur name" />
</form>
</body>
</html>
<!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 runat="server">
<title></title>
<script language="javascript">
function OnControlFocus(el)
{
if(el.value == "请你输入要搜索的信息")
el.value = "";
el.select();
}
function OnControlBlur(el)
{
if(el.value == "")
el.value = "请你输入要搜索的信息";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" Text="请你输入要搜索的信息" onmouseover="OnControlFocus(this)" onblur="OnControlBlur(this)" runat="server"></asp:TextBox>
</div>
</form>
</body>
</html>
--------------------编程问答-------------------- textbox1.Attribute.Add("onmouseout","Javascript:document.Form1.文本框.value=''"); --------------------编程问答-------------------- <asp:TextBox ID="TextBox1" runat="server" onfocus="if(this.value=='plz enter...')this.value=''" onblur="if(this.value=='')this.value='plz enter...'" >plz enter...</asp:TextBox> --------------------编程问答-------------------- 好热闹啊
呵呵 --------------------编程问答--------------------
同意四楼 --------------------编程问答-------------------- keypress 事件里写清空代码也可以吧。 --------------------编程问答-------------------- private --------------------编程问答--------------------
fava--------------------编程问答--------------------
这个很不错!! 楼主试试! --------------------编程问答-------------------- 前台的
鼠标移过去不会消失- -
点击才会
<asp:TextBox ID="TextBox3" runat="server" Font-Bold="True" ForeColor="#C00000" Height="16px"
MaxLength="5" OnFocus="javascript:if(this.value=='请你输入要搜索的信息') {this.value=''}"
OnBlur="javascript:if(this.value==''){this.value='请你输入要搜索的信息'}"
Width="50px">请你输入要搜索的信息</asp:TextBox>
补充:.NET技术 , ASP.NET