javascript中用if 条件怎么进行判断文本校验
1、javascript 做客户端验证,比如是否为空,正则匹配,如果需要后台验证的(如是否唯一)需要用ajax访问后台,处理返回结果便可,下面给大家做个示范。

3、var xmlHttp;function createXmlHttp() {if (window.XMLHttpRequest) { xmlHttp = new XMLHttpRequest();} else if (window.ActiveXObject) { xmlHttp = new ActiveXObject("MIcrosoft.XMLHttp");}}function send(url) {createXmlHttp();xmlHttp.open("GET", url, true);xmlHttp.onreadystatechange = processRequest;xmlHttp.send(null);}function processRequest() {if (xmlHttp.readyState == 4) { if (xmlHttp.status == 200) { var myfont = document.getElementById("name");//这个name跟html页面的name是对应的,不用改 while (myfont.hasChildNodes()) { myfont.removeChild(myfont.firstChild); } var text = document.createTextNode(); text.nodeValue = xmlHttp.responseText; myfont.appendChild(text); }}}-----------------------------------------------------------------------------------

5、dao:public int check(String loginName){ Session ss=HibernateSessionFactory.getSession(); ss.beginTransaction(); Query q=ss.createQuery("select loginName from Login where loginName='"+loginName+"'"); List list=q.list(); ss.getTransaction().commit(); ss.close(); return list.size();}----------------------------------------------------------------------------------------------------------------------html: <tr> <td width="100" align="right"> 用户名: </td> <td align="left"> <input type="text" name="loginName" /><input type="button" value="检查用户名" onclick="checkLoginName()"> <font color="red" size="2px" id="name"></font></td> </tr>
