Project

General

Profile

2013年05月分享(卫宁)

技术文档
06/06/2013

一、js的一些常用验证,见附件
二、js千位符号
<script>
function cc(s){
if(/[^0-9\.]/.test(s)) return "invalid value";
s=s.replace(/^(\d*)$/,"$1.");
s=(s+"00").replace(/(\d*\.\d\d)\d*/,"$1");
s=s.replace(".",",");
var re=/(\d)(\d{3},)/;
while(re.test(s))
s=s.replace(re,"$1,$2");
s=s.replace(/,(\d\d)$/,".$1");
return "¥" + s.replace(/^\./,"0.")
}
</script>
三、JQUERY移动光标到指定位置
<script>
function move(){
var position = 13;
var txtFocus = document.getElementById("txt");
if ($.browser.msie) {
var range = txtFocus.createTextRange();
range.move("character", position);
range.select();
}
else {
//obj.setSelectionRange(startPosition, endPosition);
txtFocus.setSelectionRange(position, position);
txtFocus.focus();
}
}
</script>

Files

js验证.txt (1.77 KB) js验证.txt 卫宁, 06/06/2013 01:13 PM