代碼如下:jsfunction QQ(id,k){var i=document.getElementById(id);if(!k.test(i)){if(id=="QQId"){alert("QQ格式錯誤或賬號位數不對!!!");}if(id=="QQpass"){alert("密碼格式錯誤或位數不對!!!");}}}html<div style=" margin-top:10px"><li style=" list-style:none; width:160px; margin:0px auto; font-size:12px; height:40px">QQ號碼:<input type="text" class="input" id="QQId" onblur="QQ('QQId',/^[1-9][0-9]{3,9}$/)" /></li><li style=" list-style:none; width:160px; margin:0px auto; font-size:12px; height:30px">QQ密碼:<input type="text" class="input" id="QQpass" onblur="QQ('QQpass',/^([a-zA-Z]{1,}\w){6,12}$/)"/> </li><img src="images/btn_login.gif" style=" margin-left:110px" /><p style=" font-size:12px; margin:10px 5px; line-height:25px"> 世界的改變不是少數人做了很多,而是每個人都做了一點點。伸出手,讓我們把愛傳遞。</p></div>不知道正則表達式作為參數時該怎么用?
1 回答

溫溫醬
TA貢獻1752條經驗 獲得超4個贊
k傳字符串就行了,你在test方法調用之前,先用此字符串new一個正則表達式對象出來就行了,
var t = new RegExp(k, 'g');
t.test(i)
這樣就可以了。
- 1 回答
- 0 關注
- 861 瀏覽
添加回答
舉報
0/150
提交
取消