asp.net中给TextBox文本框添加水印,不影响正常使用

具体代码如下:

<head id="Head1" runat="server">
    <title>填写备忘录信息</title>
    <script type="text/javascript">
        function watermark(id, value) {
            var obj = document.getElementById(id);
            obj.value = value;
            obj.style.cssText = "color:Gray";
            //获取焦点事件
            obj.onfocus = function () {
                this.style.cssText = "color:gainsboro";
                if (this.value == value) {
                    this.value = '';
                }
            };
            //失去焦点事件
            obj.onblur = function () {
                if (this.value == "") {
                    this.value = value;
                    this.style.cssText = "color:Gray";
                }
                else {
                    this.style.cssText = "color:gainsboro";
                }
            };
        }
        window.onload = function () {
            var arr = [{ 'id': 'TextBox1', 'desc': '请输入您的备忘录标题...' }, { 'id': 'TextBox2', 'desc': '请输入备忘录内容...'}];
            for (var i = 0; i < arr.length; i++) {
                watermark(arr[i].id, arr[i].desc);
            }
        };
    </script>
    <style type="text/css">
        .css1{
            width:500px;
            height:26px;
        }
        .css2{
            width:500px;
            height:270px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table style="width:500px;height:400px" align="center">
            <tr>
                <td style="width:500px;height:35px; font-weight: bold;" align="center">
                    填写备忘录信息
                </td>
            </tr>
            <tr>
                <td style="width:500px;height:30px;">
                    <asp:TextBox ID="TextBox1" runat="server" CssClass="css1"></asp:TextBox>

                </td>
            </tr>
            <tr>
                <td style="width:500px;height:270px">
                    <asp:TextBox ID="TextBox2" runat="server" CssClass="css2" TextMode="MultiLine"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td style="width:500px;height:30px" align="left">
                    <asp:CheckBox ID="CheckBox_Remind" runat="server" Text="邮件提醒" />
                </td>
            </tr>
            <tr>
                <td style="width:500px;height:35px" align="center">
                    <asp:Button ID="Button1" runat="server" Height="22px" Text="保存" Width="50px" />
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值