前端开发js*符号替换部分信息

客户端前端怎么开发
前端开发主界面要怎么写
前端开发的职业规划怎么写

html 代码

<!DOCTYPE html>
    <head>
        <meta charset=”utf-8″ />
        <meta
            name=”viewport”
            content=”maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0″
        />
        <meta
            name=”format-detection”
            content=”telephone=no,email=no,date=no,address=no”
        />
        <meta name=”apple-mobile-web-app-capable” content=”yes” />
        <!–ios拖动隐藏浏览器底部工具栏–>
        <title>js*符号替换部分信息</title>
        <meta name=”description” content=”” />
        <meta name=”keywords” content=”” />
        <link rel=”icon” href=”data:image/ico;base64,aWNv” />
        <!– 避免favicon.ico请求404 –>
        <link href=”” rel=”stylesheet” />
    </head>
    <body>
        <section>
            <p>
                <strong>显示前3位和后3位:</strong>
                <span id=”hiddenMiddle”></span>
            </p>
            <p><strong>屏蔽前4位:</strong> <span id=”hiddenFront”></span></p>
            <p><strong>屏蔽后4位:</strong> <span id=”hiddenEnd”></span></p>
        </section>
        <script type=”text/javascript”>
            var number = ‘15867135743’
            //调用replaceSymbol方法
            var hiddenMiddle = document.getElementById(‘hiddenMiddle’)
            hiddenMiddle.innerHTML = replaceSymbol(number, 3, 3)
            //调用replaceSymbolFront方法
            var hiddenFront = document.getElementById(‘hiddenFront’)
            hiddenFront.innerHTML = replaceSymbolFront(number, 4)
            //调用replaceSymbolEnd方法
            var hiddenEnd = document.getElementById(‘hiddenEnd’)
            hiddenEnd.innerHTML = replaceSymbolEnd(number, 4)
            //str参数表示要操作的字符串,frontLen参数表示要显示前几位,endLen参数表示要显示后几位
            function replaceSymbol(str, frontLen, endLen) {
                var symbolLen = str.length – frontLen – endLen
                var symbol = ”
                for (var i = 0; i < symbolLen; i++) {
                    symbol += ‘*’
                }
                return (
                    str.substring(0, frontLen) +
                    symbol +
                    str.substring(str.length – endLen)
                )
            }
            //str参数表示要操作的字符串,frontLen参数表示要屏蔽最前面几位
            function replaceSymbolFront(str, frontLen) {
                var symbolLen = str.length – frontLen
                var symbol = ”
                for (var i = 0; i < frontLen; i++) {
                    symbol += ‘*’
                }
                return symbol + str.substring(frontLen)
            }
            //str参数表示要操作的字符串,endLen参数表示要屏蔽最后几位
            function replaceSymbolEnd(str, endLen) {
                var symbolLen = str.length – endLen
                var symbol = ”
                for (var i = 0; i < endLen; i++) {
                    symbol += ‘*’
                }
                return str.substring(0, symbolLen) + symbol
            }
        </script>
    </body>
</html>
应届毕业生怎么做前端开发
前端开发 分页怎么做
mvc 开发 前端怎么做
» 本文来自:前端开发者 » 《前端开发js*符号替换部分信息》
» 本文链接地址:https://www.rokub.com/7942.html
» 您也可以订阅本站:https://www.rokub.com
赞(0)
64K

评论 抢沙发

评论前必须登录!