您的位置:首页 > Web前端 > JavaScript

js之2016.8.7

2016-08-07 16:19 411 查看
           <input type="text" name="textbox" value="荣耀8" data-default="荣耀8" style="width:80%;height:36px;border:none;" onclick="text_click(this);" onblur="text_blur(this);"  />

                <input type="button" value="搜 索" style="width:20%;height:36px;background:#01B3E1;border:none;float:right;" onclick="submit_click(this);" /> 

<script>

    function text_click( txtSef ) {

        if ( txtSef.value == txtSef.getAttribute( 'data-default' ) ) {

            txtSef.value = '';

        }

    }

        function text_blur( txtSef ) {

            if ( txtSef.value == '' ) {

                txtSef.value = txtSef.getAttribute( 'data-default' );

            }

        }

        function text_focus( txtSef ) {

            alert( '光标进来了' );

        }

        function submit_click( btSef ) {

            var textbox = document.getElementsByName( 'textbox' )[ 0 ];

            //if ( textbox.value == '' || textbox.value == textbox.getAttribute( 'data-default' )) {

            if ( textbox.value == '' || textbox.value == getTextBoxDefaultValue( textbox ) ) {

                alert( '请输入搜索内容' );

                textbox.value = '';

                textbox.focus();

                return;

            }

            //alert( '您要搜索的内容为:' + textbox.value );

            location = '/list.aspx?query=' + encodeURIComponent( textbox.value );

        }

        function getTextBoxDefaultValue( txtSef ) {

            return txtSef.getAttribute( 'data-default' );

        }

    </script>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: