欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JavaScript中操作字符串之localeCompare()方法的使用

 更新時間:2015年06月06日 10:59:48   投稿:goldensun  
這篇文章主要介紹了JavaScript中操作字符串之localeCompare()方法的使用,是JS入門學習中的基礎知識,需要的朋友可以參考下

 這個方法返回一個數(shù)字表示參考字符串是否到來之前或之后或相同的排序順序給定的字符串。
語法

string.localeCompare( param )

下面是參數(shù)的詳細信息:

  •     param : 字符串對象進行比較的字符串

返回值:

  •     0 : 字符串匹配100%
  •     1 : 不匹配,參數(shù)值來自于語言環(huán)境的排序順序字符串對象的值之前
  •     -1 : 不匹配,參數(shù)值來自于語言環(huán)境的排序順序字符串對象的值之后

例子:

<html>
<head>
<title>JavaScript String localeCompare() Method</title>
</head>
<body>
<script type="text/javascript">
var str1 = new String( "This is beautiful string" );
var index = str1.localeCompare( "XYZ" );
document.write("localeCompare first :" + index ); 

document.write("<br />" ); 

var index = str1.localeCompare( "AbCD ?" );
document.write("localeCompare second :" + index ); 

</script>
</body>
</html>

這將產(chǎn)生以下結(jié)果:

localeCompare first :-1
localeCompare second :1 

相關文章

最新評論