可以
<input type="button" onclick="haha('123',/\d/)" />
<script>
function haha(str,reg){
    alert(reg.test(str));
}
</script>

解决方案 »

  1.   

    function haha(str,reg){
        alert(new RegExp('reg').test(str));
    }
      

  2.   

    function   haha(str,reg){
            alert(new   RegExp(reg).test(str));
    }
      

  3.   

    onblur="okup('1231',/\d/)"
    ---
    function okup(str,reg)

        alert(new RegExp('reg').test(str));
    }我试过了,还是不行呀!另外我不需要alert,只需要如下即可
            if(!patrn.exec(document.getElementById(id).value)) 
            { 
                ...
            }