分享

jsp与js中的常见错误

 怀念真正的我 2010-08-26
<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<s:include value="/jsp/pub/header.jsp"/>
<script language="javascript">
$(document).ready(function() {    
 //$("#login").click(function(){
 //alert(11);
 //});
});
<!----登录的前台验证------------>
function login(){
 if( $("#name").val() == ""){
  alert("用户名不能为空");
  return;
 }else if($("#name").val().length <3||$("#name").val().length>10){
  alert("用户名长度过长或过短");
  return;
 }else if($("#pwd").val() == ""){
  alert("密码不能为空");
  return;
 }else if($("#pwd").val().length !=6){
  alert("密码长度为6位");
  return;
 }
 $("#frm")[0].submit();
}
//回车响应
$(document).keypress(function(e){
 var active = document.activeElement.id;
    if(e.keyCode == '13') {
     login();
    }
});
</script>
//____________________________________________________________________________________________________________
<script language="javascript">
function showOrClose(){
 var status=$("#welcome").attr("style");
 status=$.trim(status.substring(9,13));
 if(status=="none"){
         $("#welcome").show();
  }else{
   $("#welcome").hide();
   }
  }
function trim(str){
 return str.replace(/(^\s*)|(\s*$)/g,"");
}
</script>
<a href="#" id="showOrClose" onclick="showOrClose()">征婚简介 </a>
<div id="hide">
  <table id="welcome"  bgcolor="greenyellow" border="2px" style="display:none;">
       <tr>
          <td>魔兽强人征婚:散件N多,会打各种副本,
                                    曾经在超越都联盟留过学,能自我定性为有蛋装,有专攻,有人品的新时代四有魔兽世界青年。
         </td>
       </tr>
  </table>
</div>
____________________________________________________________________________________________________________
<s:form action="LoginAction!login" theme="simple" id="frm">
用户名:<s:textfield name="user.name" id="name" maxlength="10"  />
密     码:<s:password name="user.pwd" id="pwd" maxlength="6" />
<br/>
<br/>
<input name="" type="button" value="登录"  onMouseOver="this.style.backgroundColor='blue';"
onMouseOut="this.style.backgroundColor='';" class="button" onclick="login()"/>
    
<input name="" type="reset" value="重置"  onMouseOver="this.style.backgroundColor='blue';"
onMouseOut="this.style.backgroundColor='';" class="button" />
    
</s:form>
<!--<span style="color:red;"><s:property value="message"/></span>
//直接引入提示信息(这种情况下应该考虑到中英文的切换问题,在这直接用将显示为1,是因为这是在LoginAction中写的,其实
在LoginAction中也可以定义为一串中文字符,但传到页面显示时就变成了一行乱码,所以在此用数字。)
--><span style="color:red;">
<s:if test="message == 1">用户名或者密码不正确</s:if>
</span>
<s:include value="/jsp/pub/footer.jsp"/>
<s:form action="LoginAction!toUpload" theme="simple" id="upLoad">
<input type="submit" value="文件上传 " />
</s:form>
错误总结:
通过上面的代码;我有三点所得,也许很白痴,但这是我学习过程中的纰漏处:
                                           (1)同一个jsp页面中可以存在多个js。(2)jsp页面中可以存在[横线,虚线].(3
                                           js文件中,通过id属性  ,修改文件的状态时,id值不能包含下划线。                      

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多