当使用JavaScript文本框里面输入启动消息显示 [英] Show message when start typing inside textbox using javascript

查看:91
本文介绍了当使用JavaScript文本框里面输入启动消息显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ASP.NETand我想显示一个文本框后面的消息时,我开始在这上面写的,我想这样做,在客户端,所以我认为JavaScript是关键。

编辑:

我的code:

 < TR>
                    &所述; TD>
                        < ASP:标签ID =Label1的=服务器文本=备用电子邮件:>< / ASP:标签>
                    < / TD>
                    &所述; TD>
                        < ASP:文本框ID =_ txtAlternateEmail=服务器的onkeyup =的TypeText(本);>< / ASP:文本框>
                    < / TD>
                < / TR>
                &所述; TR>
                    &所述; TD>
                        < ASP:标签ID =Label2的=服务器文本=安全提问:>< / ASP:标签>
                    < / TD>
                    &所述; TD>
                        < ASP:文本框ID =_ txtSecurityQuestion=服务器>< / ASP:文本框>
                    < / TD>
                < / TR>

和JavaScript

 <脚本类型=文/ JavaScript的>
    功能的TypeText(TB){
        变种mySpanElement =的document.getElementById(_ txtSecurityQuestion);
        mySpanElement.innerText = tb.value;
    }
< / SCRIPT>


解决方案

您可以在文本框中处理的onkeyup 事件

 < ASP:文本框ID =_ txtAlternateEmail=服务器的onkeyup =的TypeText(本);>
< / ASP:文本框>

它调用的TypeText 方法。在你的的TypeText 方法,您可以设置跨度(或任何HTML元素)到文本框的文本。

 函数的TypeText(TB)
{
     VAR mytextbox =的document.getElementById('<%= _ txtSecurityQuestion.ClientID%GT;');
     mytextbox.value = tb.value;
}

I'm using ASP.NETand I want to show message behind a textbox when I start to write in it, I want to do that on the client side so I think javascript is the key.

Edit :

My code:

<tr>
                    <td>
                        <asp:Label ID="Label1" runat="server" Text="Alternate Email :"></asp:Label>
                    </td>
                    <td>
                        <asp:TextBox ID="_txtAlternateEmail" runat="server" onkeyup="typetext(this);"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:Label ID="Label2" runat="server" Text="Security Question :"></asp:Label>
                    </td>
                    <td>
                        <asp:TextBox ID="_txtSecurityQuestion" runat="server"></asp:TextBox>
                    </td>
                </tr>

and the javascript

<script type="text/javascript">
    function typetext(tb) {
        var mySpanElement = document.getElementById("_txtSecurityQuestion");
        mySpanElement.innerText = tb.value;
    }
</script>

解决方案

You could handle the onkeyup event in the textbox

<asp:TextBox ID="_txtAlternateEmail" runat="server" onkeyup="typetext(this);">
</asp:TextBox>

which calls the typetext method. In your typetext method, you can set the span (or whatever HTML element) to the text of the textbox.

function typetext(tb)
{
     var mytextbox = document.getElementById('<%=_txtSecurityQuestion.ClientID %>');
     mytextbox.value = tb.value;
}

这篇关于当使用JavaScript文本框里面输入启动消息显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆