截取abcdefg右边的fg
方法一
<script>
string="abcdefg"
alert(string.substring(string.length-2,string.length))
</script>
方法2
<script>
alert("abcdefg".match(/.*(.{2})/)[1])
</script>
<script>
alert("abcdefg".match(/.{2}$/))
</script>
方法3
<script>
alert("abcdefg".slice(-2)) //推荐这个,比较简单,-2表示取右边两个字符
</script>
最后
以上就是高兴钥匙最近收集整理的关于javascript从右边截取指定字符串的三种实现方法的全部内容,更多相关javascript从右边截取指定字符串内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复