首页 > Web开发 > 详细

网页中搜索框效果原理。

时间:2014-02-16 17:49:14      阅读:397      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣bubuko.com,布布扣
哈哈,只是简单的原理(代码可能不是这样写的),明白原理就好~
bubuko.com,布布扣
    <title></title>
    <style type="text/css">
        .Cls {
            width: 200px;
        }

        .ClsOutput {
            background-color: silver;
            font-style: italic;
            font-family: 楷体;
        }

        .ClsInput {
            background-color: white;
        }
    </style>
</head>
<body style="font-style: italic">
</body>
</html>
<script type="text/javascript">
    var val = ‘请输入搜索内容‘;
    var Input = function () {
        this.className = ‘Cls ClsInput‘;
        this.value = ‘‘;
        this.backgroundColor = ‘white‘;
    };
    var Output = function () {
        if (this.value == ‘‘) {
            this.className = ‘Cls ClsOutput‘;
            this.value = val;
        }
    };
    window.onload = function () {
        var txt = document.createElement(‘input‘);
        //txt.type = ‘text‘;
        //txt.style.width = ‘100px‘;
        //txt.style.background = ‘gray‘;
        //txt.style.fontStyle = ‘italic‘;
        //txt.style.fontFamily = ‘楷体‘;
        txt.className = ‘Cls ClsOutput‘;
        txt.id = ‘Search‘;
        txt.value = val;

        txt.onfocus = Input;
        txt.onblur = Output;
        document.body.appendChild(txt);
    };
</script>
bubuko.com,布布扣

 

网页中搜索框效果原理。

原文:http://www.cnblogs.com/wjshan0808/p/3551020.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!