我有一个如下所示的 asp:TextBox
<asp:TextBox runat="server" AutoPostBack="True" ID="txtG1" ontextchanged="txtG1_TextChanged" onmouseout="javascript:RefreshIt(this)"/>
和一个 Javascript 函数 RefreshIt(),每次我鼠标移开 文本框时都会正确触发。
我试图让 mouseout 事件触发 asp:TextBox 的 ontextchanged 事件。
各种 Stck Overflow 帖子推荐了以下技术,但似乎不起作用:
function RefreshIt(selectObj){
selectObj.ontextchanged();
}
function RefreshIt(selectObj){
selectObj.fireEvent('ontextchanged');
}
如有任何帮助,我们将不胜感激。
请您参考如下方法:
参见:https://stackoverflow.com/a/3777/892536
使用此链接,我能够得出与您正在寻找的结果相同的结果。不确定这是否适合您的应用程序,但它有效:
ASPX:
更改了 RefreshIt 函数以使用参数进行回发:
<script type="text/javascript">
function RefreshIt(selectObj) {
__doPostBack('<%= Page.ClientID %>', selectObj.name);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox runat="server" AutoPostBack="True" ID="txtG1" OnTextChanged="txtG1_TextChanged"
onmouseout="javascript:RefreshIt(this);" />
<br />
<br />
Text Changed:
<asp:Label ID="Label1" runat="server"></asp:Label>
</div>
</form>
</body>
代码隐藏:
向页面添加“IPostBackEventHandler”并处理“RaisePostBackEvent”函数:
public partial class _Default : System.Web.UI.Page, IPostBackEventHandler
{
protected void Page_Load(object sender, EventArgs e)
{
}
public void RaisePostBackEvent(string Arg)
{
if (txtG1.ID == Arg)
txtG1_TextChanged(txtG1, null);
}
protected void txtG1_TextChanged(object sender, EventArgs e)
{
Label1.Text = System.DateTime.Now.ToString();
}
}
