checkbox勾选判断代码分析
varxieYi=document.getElementById("xieYi"); if(!xieYi.checked){ alert("请先阅读并勾选注册协议!"); return; }
最开始这样写,不过并不是所有的情况都需要勾选这个协议,协议有时不会在前台页面显示,所以改了第二种
varxieYi=document.getElementById("xieYi"); if(!xieYi==null&&!xieYi.checked){ alert("请先阅读并勾选注册协议!"); return; }
当xieYi不存在的时候,xieYi为null,判断xieYi不为null的时候并且xieYi没有勾选的时候就alert。
可惜,这段代码没有发挥预想中的作用。
最后发现是判断xieYi写错了。
最终版:
varxieYi=document.getElementById("xieYi"); if(xieYi!=null&&!xieYi.checked){ alert("请先阅读并勾选注册协议!"); return; }