`
zcz123
  • 浏览: 157260 次
  • 性别: Icon_minigender_1
  • 来自: 厦门
社区版块
存档分类

几个js方法

阅读更多

javascript 用来去空格
function Trim(str)
{
  return  str.replace(/^\s*(.*?)[\s\n]*$/g,  '$1');
}
随机产生几个数
<script language="javascript">
    function vvCode(k){
        eval(A=new Array(k))
        for(i=0;i<k;i++){
        A[i]=parseInt(Math.random()*10)
        document.write(A[i])
        }
    }
    vvCode(5)
   //javascript可以通过eval函数指定产生的验证码位数,更爽一点
</script>
一个页码生成的方法
    public String getJs(int index)
    {
        String js="<script type=\"text/javascript\">" +
                "lastNo=0;" +
                "function re(menu_no)" +
                "{" +
                    "if(lastNo!=menu_no)" +
                    "{" +
                        "cur=menu_no+1;" +
                        "lastNo=menu_no;" +
                        "rest();" +
                    "}" +
                    "else" +
                    "{" +
                        "cur=100;" +
                    "}" +
                    "document.getElementById(\"board\"+menu_no).style.visibility=\"visible\";" +
                "}" +
                "function rest()" +
                "{" +
                    "for(i=1;i<="+index+";i++)" +
                    "{" +
                        "document.getElementById(\"hor\"+i).style.top=20*i;" +
                        "document.getElementById(\"board\"+i).style.visibility=\"hidden\";" +
                    "}" +
                    "menu_num="+index+";" +
                    "act=1;" +
                    "height=120+20;" +
                    "speed=0;" +
                    "posY=0;" +
                 "}" +
                 "function huke()" +
                 "{" +
                     "if(act==1&&cur<100)" +
                     "{" +
                         "speed=(height-posY)*0.69+speed*0.6;" +
                         "posY+=speed;" +
                         "for(i=cur;i<=menu_num;i++)" +
                         "{" +
                             "document.getElementById(\"hor\"+i).style.top=posY+(i-2)*20;" +
                          "}" +
                          "if(Math.abs(height-posY)<0.5)" +
                          "{" +
                              "for(i=cur;i<=menu_num;i++)" +
                              "{" +
                                  "document.getElementById(\"hor\"+i).style.top=height+(i-2)*20;" +
                              "}" +
                              "act=0;" +
                          "}" +
                          "setTimeout(\"huke()\",50);" +
                      "}" +
                  "}" +
                  "</script>";
        return js;

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics