<script>
string="abcdefg"
alert(string.substring(string.length-2,string.length))
</script>
<script>
alert("abcdefg".match(/.*(.{2})/)[1])
</script>
<script>
alert("abcdefg".match(/.{2}$/))
</script>
<script>
alert("abcdefg".slice(-2))
</script>
<script language="javascript">
String.prototype.right = function(n) {
return this.slice(this.length - n-1);
}
var s = 'abcdefg';
window.alert(s.right(2));
</script>
http://hi.baidu.com/webnum/blog/item/a1833158983f033c2834f0b0.html
http://bbs.51js.com/thread-54383-1-1.html
在线测试工具:
http://www.w3school.com.cn/tiy/t.asp?f=jseg_slice_array