Text box watermark prompt effect of the simple implementation code

  • 2020-03-30 02:07:32
  • OfStack


<!doctype html>
<html>
<head>
    <title></title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
    <style type="text/css">
        #divTips{
            filter:alpha(opacity=30); 
            -moz-opacity:0.3; 
            opacity:0.3;
            position: absolute;width: 600px; height: 400px;display:none;color:red;z-index:10;padding:10px;
        }
    </style>
    <script type="text/javascript">
        $(function () {
            var $txtNote = $("#txtNote");
            var $divTips = $("#divTips");
            $txtNote.focus(function () {
                //Hide while in focus
                $divTips.hide();
            }).blur(function () {
                //When leaving, show if it is empty, otherwise hide. Then locate
                $divTips.toggle($txtNote.val() == "")
                    .css({
                        "left": $txtNote.position().left,
                        "top" : $txtNote.position().top
                    });
            });
            $divTips.click(function () {
                $txtNote.focus();
            });
            $txtNote.blur();
        });
    </script>
</head>
<body>
     Message board <br />
    <textarea id="txtNote" style="width: 600px; height: 400px;"></textarea>
    <div id="divTips">
         Dear, welcome to visit, have what say to write down !!<br />
        ( Leave yours in the box below name,  Please leave your contact information at your convenience )
    </div><br />
    <input type="text" value=" The name " /> <input type="text" value=" Mobile phone /QQ/ ... " />
</body>
</html>

Related articles: