手机号和运营商的判断
if ( ( /^1(3|4|5|6|7|8|9)\d{9}$/ . test ( phoneNum) ) ) {
alert ( "号码格式正确" ) ;
} else {
alert ( "号码格式错误,请重新填写" ) ;
}
function checkMobile ( telphone) {
var isChinaMobile = /^1(3[4-9]|5[012789]|8[23478]|4[7]|7[28]|9[8])\d{8}$/ ;
var isChinaUnion = /^1(3[0-2]|5[56]|8[56]|4[5]|7[56]|6[6])\d{8}$/ ;
var isChinaTelcom = /^1(3[3])|(8[019])|(9[139])|(7[37])|(5[3])\d{8}$/ ;
if ( isChinaMobile. test ( telphone) ) {
return "中国移动" ;
}
if ( isChinaUnion. test ( telphone) ) {
return "中国联通" ;
}
if ( isChinaTelcom. test ( telphone) ) {
return "中国电信" ;
}
}
判断运营商后,默认选择运营商
< span class = " tips" style =" display : inline; " id = " show-mobile" > </ span>
< div class = " form2" >
< label class = " type1" >
< div class = " clearfix" id = " choose-mobile" >
< span class = " a-num" RMB = " 中国移动" > 中国移动< img
class = " select-img" src = " images/jst/triangle.png" alt = " " > </ span>
< span class = " a-num" RMB = " 中国联通" > 中国联通< img
class = " select-img" src = " images/jst/triangle.png" alt = " " > </ span>
< span class = " a-num" RMB = " 中国电信" > 中国电信< img
class = " select-img" src = " images/jst/triangle.png" alt = " " > </ span>
</ div>
</ label>
</ div>
$ ( "#show-mobile" ) . bind ( 'DOMNodeInserted' , function ( e) {
var showText = $ ( this ) . text ( ) ;
var num = 0 ;
if ( showText == "中国移动" ) {
num = 0 ;
}
if ( showText == "中国联通" ) {
num = 1 ;
}
if ( showText == "中国电信" ) {
num = 2 ;
}
var sdiv = $ ( "#choose-mobile span" ) . eq ( num) ;
sdiv. addClass ( "active" ) ;
} ) ;
span标签内容改变事件
$ ( "#spanId" ) . bind ( 'DOMNodeInserted' , function ( e) {
alter ( $ ( this ) . text ( ) ) ;
} ) ;
获取标签组的被选中的内容
< li>
< div class = " items-flex" >
< span class = " items-sp1" > 10元</ span>
</ div>
</ li>
< li>
< div class = " items-flex" >
< span class = " items-sp1" > 20元</ span>
</ div>
</ li>
< li>
< div class = " items-flex" >
< span class = " items-sp1" > 30元</ span>
</ div>
</ li>
var priceStr = $ ( ".items-flex.active .items-sp1" ) . eq ( 0 ) . text ( ) ;
alter ( priceStr) ;
输入框内容发生改变事件
$ ( "#mobile" ) . bind ( "input propertychange" , function ( ) {
alter ( $ ( this ) . val ( ) ) ;
} ) ;
循环数组
当给定的值,满足数组中的某个key值,取出这个key所对应的值
function chooseList ( priceNum) {
for ( var key in list) {
if ( key == priceNum) {
alter ( list[ key] ) ;
}
}
}
取出通过地址栏传过来的值
var searchURL = window. location. search;
searchURL = searchURL. substring ( 1 , searchURL. length) ;
var typeId = searchURL. split ( '=' ) ;
alter ( typeId[ 1 ] ) ;
去空格
function trimAll ( str) {
return str. replace ( /[^0-9]/g , '' ) . replace ( /\s|-/g , '' ) ;
}
加空格
function formatPhoneNumber ( str) {
return $. trim ( str. substring ( 0 , 3 ) + ' ' + str. substring ( 3 , 7 ) + ' '
+ str. substring ( 7 , 11 ) )
}