localeCompare()方法

2017-06-16 14:53:00
admin
原创
276
<!DOCTYPE html>
<html>
<head>
    <title>String Type localeCompare() Example</title>
    <script type="text/javascript">
    
        var stringValue = "yellow";       
        alert(stringValue.localeCompare("brick"));  //1
        alert(stringValue.localeCompare("yellow")); //0
        alert(stringValue.localeCompare("zoo"));    //-1
        
        //preferred technique for using localeCompare()
        function determineOrder(value) {
            var result = stringValue.localeCompare(value);
            if (result < 0){
                alert("The string 'yellow' comes before the string '" + value + "'.");
            } else if (result > 0) {
                alert("The string 'yellow' comes after the string '" + value + "'.");
            } else {
                alert("The string 'yellow' is equal to the string '" + value + "'.");
            }
        }
        
        determineOrder("brick");
        determineOrder("yellow");
        determineOrder("zoo");

    </script>
</head>
<body>

</body>
</html>
文章分类
联系我们
电话: 18902328227
Email: 2689701946@qq.com
QQ: 2689701946
微信: 18902328227
地址: 广州番禺区繁华路
  • 在线客服
  • 关注微信
  • 联系电话
    • 欢迎咨询
    • 欢迎加入QQ群 303257430
  • 公众号:源宝网络
    • 联系电话及微信号 18902328227