请问javascript高手,急 可以;但是到浏览器端时,JSP已经运行过了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可以,牢记在后台时只有jsp代码,javascript当字符串.到前台后,没有jsp代码,都是根据条件产生的html等代码。 我是这样设计的我在提交表单的时候进行有效性判断我写了一个函数进行判断比如有些文本框不能为空,但是这些不能为空的文本框我是根据数据库表中对应的值确定的,所以我在函数中应该嵌入jsp代码,但是运行的时候编译器不认,请问是什么问题 使用style="width:100%;isnullable:0",其中isnullable用JSP代码或手动给出<script language="JavaScript"><!--function MM_goToURL() { //v3.0 var i, args=MM_goToURL.arguments; document.MM_returnValue = false; for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");}String.prototype.Trim = function(){ return this.replace(/(^\s*)|(\s*$)/g, "");}function check(){ var inputs=document.frmAdd.all.tags("INPUT"); for(var i=0;i<inputs.length;i++){ //去掉所填项目左右空格 var tmp=inputs[i].value; inputs[i].value=tmp.Trim(); //如果必填项未填,要求填写 if(inputs[i].value.length<=0 && inputs[i].style.isnullable==0){ alert("带有'*'号的项目为必填项目,请全部填写。"); return false; } //如果有File字段且不为空,则改变表单的提交类型 if(inputs[i].value.length>0 && inputs[i].type.toUpperCase()=="FILE"){ document.frmAdd.enctype="multipart/form-data"; } }//end for(var i=0;i<inputs.length;i++) if(document.frmAdd.enctype=="multipart/form-data") document.frmAdd.action=""; else document.frmAdd.action="PDMAdd.jsp"; return true;}//--></script></head><body><form name=frmAdd method="POST" onsubmit="return check()" > <div align="center"> <table border="1" cellspacing="0" width="60%" bgcolor="#F0F8FF" bordercolorlight="#11B1FF" bordercolordark="#F0F8FF"> <tr> <td width="100%" bgcolor="#0080C0" height="20"> <div align="center"> <p><b><font color="#FFFFFF">添加新记录</font></b> </div> </td> </tr> <tr align="center"> <td width="100%"> <table bgColor=#f0f8ff border=1 borderColorDark=#ecf5ff borderColorLight=#4da6ff cellSpacing=0 width="100%"> <tr> <td width="38%" align="left" height="30" nowrap> <b><font color="#0080C0"> 权限编码<font color=#FF0000 > *</font></font></b></td> <td width="62%" height="30"> <input type="Text" value= "" name="Code" size="70" class="smallinput" style="width:100%;isnullable:0"> </td> </tr> <tr> <td width="38%" align="left" height="30" nowrap> <b><font color="#0080C0"> 权限级别<font color=#FF0000 > *</font></font></b></td> <td width="62%" height="30"> <input type="Text" value= "" name="Class" size="70" class="smallinput" style="width:100%;isnullable:0"> </td> </tr> <tr> <td width="38%" align="left" height="30" nowrap> <b><font color="#0080C0"> 说明<font color=#FF0000 > *</font></font></b></td> <td width="62%" height="30"> <input type="Text" value= "" name="Re" size="70" class="smallinput" style="width:100%;isnullable:0"> </td> </tr> </table> </td> </tr> </table> </div> <div align="center"> <p> <input type="submit" value=" 确 定 " name="cmdok" class="buttonface" > <input type="reset" value=" 复 原 " name="cmdcancel" class="buttonface"> <input type="button" value=" 返 回 " name="cmdreturn" class="buttonface" onclick="MM_goToURL('self','http://localhost:8080/PDMShow.jsp');return document.MM_returnValue"> </p> </div></form></body></html> 你说的方法是可行不过你的意思是javascript函数中不能嵌入jsp代码吧 可以嵌入呀。test.jsp:strIsNullable=0;<input name=like style="width:100%;isnullable:<%=strIsNullable%>">到浏览器端时,代码就会变成:<input name=like style="width:100%;isnullable:0">这个不需要解释吧?只是弄不明白你所谓“嵌入”的概念:javascript和JSP代码是不能同时起作用的。 在函数外是能够嵌入的我是说函数中能否嵌入jsp代码 jquery小问题 extjs gid如何动态显示scrollbar列 各位JS高手,想用JS打印这个JSON字符串啊 关于生成层 js牛人在哪里? javascript有个错误,为什么有的机子能显示,有的机子不能显示? 下拉列表框的问题??? 紧急求助!!!紧急求助!!!紧急求助!!! 有没有什么比较快的算法或者函数能够取小数位数的? 如何在page上动态创建一个img图片? 请问如何(用javascript )将当前网页上的图片和当前网页下载到本地硬盘?? 怎样使div位置适应不同的分辨率?
jsp代码,都是根据条件产生的html等代码。
我在提交表单的时候进行有效性判断
我写了一个函数进行判断
比如有些文本框不能为空,但是这些不能为空的文本框我是根据数据库表中对应的值确定的,所以我在函数中应该嵌入jsp代码,
但是运行的时候编译器不认,请问是什么问题
<!--
function MM_goToURL() { //v3.0
var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}String.prototype.Trim = function(){
return this.replace(/(^\s*)|(\s*$)/g, "");
}function check(){
var inputs=document.frmAdd.all.tags("INPUT"); for(var i=0;i<inputs.length;i++){
//去掉所填项目左右空格
var tmp=inputs[i].value;
inputs[i].value=tmp.Trim(); //如果必填项未填,要求填写
if(inputs[i].value.length<=0 && inputs[i].style.isnullable==0){
alert("带有'*'号的项目为必填项目,请全部填写。");
return false;
} //如果有File字段且不为空,则改变表单的提交类型
if(inputs[i].value.length>0 && inputs[i].type.toUpperCase()=="FILE"){
document.frmAdd.enctype="multipart/form-data";
}
}//end for(var i=0;i<inputs.length;i++) if(document.frmAdd.enctype=="multipart/form-data") document.frmAdd.action="";
else document.frmAdd.action="PDMAdd.jsp";
return true;
}
//-->
</script></head>
<body>
<form name=frmAdd method="POST" onsubmit="return check()" >
<div align="center">
<table border="1" cellspacing="0" width="60%"
bgcolor="#F0F8FF" bordercolorlight="#11B1FF" bordercolordark="#F0F8FF">
<tr>
<td width="100%" bgcolor="#0080C0" height="20">
<div align="center">
<p><b><font
color="#FFFFFF">添加新记录</font></b>
</div>
</td>
</tr>
<tr align="center">
<td width="100%">
<table bgColor=#f0f8ff border=1 borderColorDark=#ecf5ff borderColorLight=#4da6ff cellSpacing=0 width="100%"> <tr>
<td width="38%" align="left" height="30" nowrap> <b><font color="#0080C0">
权限编码<font color=#FF0000 > *</font></font></b></td>
<td width="62%" height="30">
<input type="Text" value=
"" name="Code" size="70" class="smallinput" style="width:100%;isnullable:0">
</td>
</tr> <tr>
<td width="38%" align="left" height="30" nowrap> <b><font color="#0080C0">
权限级别<font color=#FF0000 > *</font></font></b></td>
<td width="62%" height="30">
<input type="Text" value=
"" name="Class" size="70" class="smallinput" style="width:100%;isnullable:0">
</td>
</tr> <tr>
<td width="38%" align="left" height="30" nowrap> <b><font color="#0080C0">
说明<font color=#FF0000 > *</font></font></b></td>
<td width="62%" height="30">
<input type="Text" value=
"" name="Re" size="70" class="smallinput" style="width:100%;isnullable:0">
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
<div align="center">
<p>
<input type="submit" value=" 确 定 " name="cmdok" class="buttonface" >
<input type="reset" value=" 复 原 " name="cmdcancel" class="buttonface">
<input type="button" value=" 返 回 " name="cmdreturn" class="buttonface" onclick="MM_goToURL('self','http://localhost:8080/PDMShow.jsp');return document.MM_returnValue">
</p>
</div>
</form>
</body>
</html>
不过你的意思是javascript函数中不能嵌入jsp代码吧
test.jsp:
strIsNullable=0;
<input name=like style="width:100%;isnullable:<%=strIsNullable%>">到浏览器端时,代码就会变成:
<input name=like style="width:100%;isnullable:0">这个不需要解释吧?只是弄不明白你所谓“嵌入”的概念:javascript和JSP代码是不能同时起作用的。
我是说函数中能否嵌入jsp代码