JavaScript自定义函数实现字符串转小写和转大写

2017-01-29 21:09:03  访问(1924) 赞(0) 踩(0)

  • 
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
        <style type="text/css">
            .btn
            {
                cursor: pointer;
                height: 25px;
                width: 80px;
                line-height: 23px;
                margin: 0px 4px;
                padding: 0 8px; *padding:02px;text-align:center;display:inline;border-radius:2px;font-size:12px;
            }</style>
    </head>
    <body>
        <h1>
            JavaScript自定义函数实现字符串转小写和转大写</h1>
        输入:<br />
        <textarea name="txt_Input" rows="2" cols="20" id="txt_Input" style="height: 100px;
            width: 99%;">www.slowx.net</textarea>
        <br />
        <br />
        <input type="button" id="btn_OK" class="btn" value="转小写" onclick="OkClick(true)" />
        <input type="button" id="btn_Up" class="btn" value="转大写" onclick="OkClick(false)" />
        <br />
        <br />
        输出:<br />
        <textarea name="txt_Output" rows="2" cols="20" id="txt_Output" style="height: 100px;
            width: 99%;"></textarea>
    </body>
    </html>
    
    <script language="javascript" type="text/javascript">
        function StrGetLowerCase(str) {
            // 转小写 //
            if (str == null)
                return true;
    
            return str.toLowerCase();
        }
        function StrGetUpperCase(str) {
            // 转大写 //
            if (str == null)
                return true;
    
            return str.toUpperCase();
        }
    
        function OkClick(isToLower) {
            var inputCtrl = document.getElementById("txt_Input");
            var outputCtrl = document.getElementById("txt_Output");
    
            var theValue = inputCtrl.value;
    
            if (isToLower)
                theValue = StrGetLowerCase(theValue);
            else
                theValue = StrGetUpperCase(theValue);
    
            outputCtrl.value = theValue;
        }
     
    
    </script>
    
    


标签:JavaScript自定义函数实现字符串转小写和转大写 

上一条:

下一条:


 

相关评论

评论加载中……
 

发表评论

类型:
内容:
  (Alt+Enter)