在文本框问题中显示默认文本。 [英] Display default text in textbox issue.

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

问题描述

如何在页面加载期间为asp.net文本框设置默认文本,并在关注时清除它们?我将Text属性设置为0,但是在设置焦点时它不会清除,如果没有任何内容可以输入到文本框中,我想保留默认值。

How do I set default text for asp.net textbox during page load and clear them when focused on? I have the Text property set to "0" but it will not clear when focus is set and I would like to keep the default value if there is nothing to input into the textbox.

推荐答案

试试这个..





try this..


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <script src="jquery-1.10.2.js" type="text/javascript"></script>
    <script type="text/javascript">


function (){

var txtbox =
(function () { var txtbox =


' #<%= txtBoxControl.ClientID%>');
var defaultText = txtbox.val();

txtbox.focus( function (){
if ( txtbox.val()== defaultText)
txtbox.val( );
});

txtbox.blur( function (){
if ( txtbox.val()。length == 0
txtbox.val(defaultText);
});

});



< / script >
< / head >
< 正文 >
< 表格 id = form1 runat = server >
< asp:TextBox ID = txtBoxControl runat = server 文字 = 某些默认值 >
< / form >
< / body < span class =code-keyword>>
< / html >
('#<%= txtBoxControl.ClientID %>'); var defaultText = txtbox.val(); txtbox.focus(function () { if (txtbox.val() == defaultText) txtbox.val(""); }); txtbox.blur(function () { if (txtbox.val().length == 0) txtbox.val(defaultText); }); }); </script> </head> <body> <form id="form1" runat="server"> <asp:TextBox ID="txtBoxControl" runat="server" Text="some default value"> </form> </body> </html>


这篇关于在文本框问题中显示默认文本。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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