function txtonfocus() {
var txt = document.getElementById("txtSearch");
txt.vaklue = "123";
}
我在文本框得到焦点时触发这个方法. 为什么不可以呢??
解决方案 »
- 怎样让TextBox在火狐下也能触发Changed事件
- asp.net中关于sql语句的问题
- 如何用PreviousPage跨页面传值?
- gridview有没有这样的功能?
- .net sql2000 数据库如何连接和添加,修改,删除 ,小弟是新手~在线等~请大家帮助
- GridView里,我点了自带的编辑按钮,怎么屏蔽其他我另加的其他按钮呢?即如何找到当前行的其他按钮?
- 中文字符传递问题
- 请问如何把本地的"localhost"改为"localhost."
- 有关创建弹出式菜单的问题(急!!!!!!!!)
- 大家看看这个问题,非常非常急,在线等!
- 下面的“精度搜索”和“字典”怎么实现啊
- iis发布项目,新建网站和新建虚拟目录的区别和优缺点?
============================
txt.value="123";
value写错了
额. 补好意思. 是打错了.
txt.value = "123" 这样子也不行.
这样子也不行.
}
<head runat="server">
<title>无标题页</title>
<script type="text/ecmascript">
function txtonfocus()
{
var t=document.getElementById("txtSearch");
t.value="123";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type=text id="txtSearch" onfocus="txtonfocus()" />
</div>
</form>
</body>
</html>
我需要用asp.net 的TextBox控件....
var txt = document.getElementById("txtSearch").value;
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!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>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>
</div>
</form>
<script>
document.getElementById("<%= txtSearch.ClientID %>").onfocus = function () {
this.value = "123";
}
</script>
</body>
</html>
this.value = "123";
}这个是可以的。asp.net服务器端控件在客户端的ID变了。你分别
alert( document.getElementById("txtSearch").length);
alert( document.getElementById("<%= txtSearch.ClientID %>").length);
看看。
<head runat="server">
<title>无标题页</title>
<script type="text/ecmascript">
function txtonfocus()
{
var t=document.getElementById("<%=this.txtSearch.ClientID%>");
t.value="123";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtSearch" runat="server"></asp:TextBox></div>
</form>
</body>
</html>using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.txtSearch.Attributes.Add("onfocus", "txtonfocus()");
}
}
<head runat="server">
<title>无标题页</title>
<script type="text/ecmascript">
function txtonfocus()
{
var t=document.getElementById("<%=this.txtSearch.ClientID%>");
t.value="123";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtSearch" runat="server"></asp:TextBox></div>
</form>
</body>
</html>using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.txtSearch.Attributes.Add("onfocus", "txtonfocus()");
}
}
function txtOnfocus() {
document.getElementById("txt1").onfocus = function () { this.value = "123"; };
}
</script>
<input type="text" name="txt1" id="txt1"/>
document.getElementById("txtSearch").value;
function txtOnfocus() {
document.getElementById("<%=this.TextBox1.ClientID %>").onfocus = function () { this.value = "123"; };
}
</script>
<input type="text" name="txt1" id="txt1"/>
<asp:TextBox ID="TextBox1" Name="111" runat="server" onfocus="txtOnfocus()"></asp:TextBox>
{
var t=document.getElementById("<%=this.txtSearch.ClientID%>");
t.value="123";
}