如何在向该文本框输入任何值之前在文本框中显示默认值 [英] How to display default value in text box before entering any value into that text box

查看:108
本文介绍了如何在向该文本框输入任何值之前在文本框中显示默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在litebox1中以lite颜色显示默认值,然后在同一文本框中输入任何值



//示例

当我们使用任何社交网站意味着我们将在文本框中输入任何名称时将面对这种类型的...之前只有我们将看到精简颜色的名称...当courser进入该文本框时...自动地它将消失

解决方案

您应该查看Ajax Control Toolkit的 TextBox水印



欲了解更多信息:

http ://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/TextBoxWatermark/TextBoxWatermark.aspx [ ^ ]



祝你好运,

OI

在文本框中使用占位符属性。



example-

< asp:TextBox ID =txtName PlaceHolder =输入你的名字 runat =server>< / asp:TextBox> 





它有效。


遵循此代码即可实现目标。



  function  onFocus(){
var txtBox = document .getElementById(' <%= TextBox1.ClientID%> ;');
if (txtBox.value == 用户名){
txtBox.value = ;
txtBox.style.backgroundColor = white;
txtBox.style.color = 黑色
}
}
function onFoucsOut(){
var txtBox = document .getElementById(' <%= TextBox1.ClientID%>'< /跨度>);
if (txtBox.value == ){
txtBox.value = 用户名;
txtBox.style.backgroundColor = Azure;
txtBox.style.color = Silver;
}
}







 < span class =code-keyword><   blockquote     class   =  FQ >  <   div     class   =  FQA < span class =code-keyword>> 引用:<   / div  < span class =code-keyword>> > <   / blockquote  < span class =code-keyword>>  


i want to show the default value in the textbox1 in lite color before entering any value into the same text box

//example
when we are using any social networking sites means we will face this type of one while entering any name in the textbox..before only we will see name in lite color...when the courser goes into that textbox..automatically it will disappear

解决方案

You should look into Ajax Control Toolkit''s TextBox Watermark .

For more info:
http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/TextBoxWatermark/TextBoxWatermark.aspx[^]

Good luck,
OI


Use Placeholder attribute inside the textbox.

example-

<asp:TextBox ID="txtName" PlaceHolder="Enter Your Name" runat="server"></asp:TextBox>



it works.


Follow this code you''ll achieve your goal.

function onFocus() {
            var txtBox = document.getElementById('<%=TextBox1.ClientID %>');
            if (txtBox.value == "User Name") {
                txtBox.value = "";
                txtBox.style.backgroundColor = "white";
                txtBox.style.color = "Black"
            }
        }
        function onFoucsOut() {
            var txtBox = document.getElementById('<%=TextBox1.ClientID %>');
            if (txtBox.value == "") {
                txtBox.value = "User Name";
                txtBox.style.backgroundColor = "Azure";
                txtBox.style.color = "Silver";
            }
        }




<blockquote class="FQ"><div class="FQA">Quote:</div> ></blockquote>


这篇关于如何在向该文本框输入任何值之前在文本框中显示默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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