var proList=document.getElementById("proList");
var pageCount=document.getElementById("page");
pc=pageCount.children[pageCount.children.length-2].innerText;
for(i=0;i<parseInt(pc);i++){
    alert(i);
    var nextPage=pageCount.children[pageCount.children.length-1];
    var title1=proList.firstChild.innerText;
    var ev=document.createEvent("HTMLEvents");
    ev.initEvent("click",false,true);
    nextPage.dispatchEvent(ev);
    nextPage.click();
}以上代码alert(i)只展现了一次,为什么呢?请大神们指教。谢谢!

解决方案 »

  1.   

    pc=pageCount.children[pageCount.children.length-2].innerText;你alert(pc)  这样一下。看这个pc是多少~·
      

  2.   

    你需要确定pageCount.children[pageCount.children.length-2].innerText;这个值是你想要的
      

  3.   

    pc的值没问题,我大概发现了问题,因为click一次后,页面就刷新了,所以只执行到一次,不知道应当如何解决。
      

  4.   

    那需要看你是否需要在点击之后就提交一次页面了,如果要这样就需要ajax了,用jquery的话非常方便的,有post与get函数,你到网上看看具体的用法吧,good luck!