2017-04-09 159 views
0

我在Firefox中测试我的问题。我点击保存按钮(这是一个输入,类型为button),它应该执行:输入按钮onclick在JSP中不起作用

onclick="checkchar()" 

,但事实并非如此。

enter image description here

我在jsp部分代码:

<script language="javascript"> 
    function checkchar(){ 

    /* 
    if(document.Form2.stationRun.value.length>2500){ 

     alert("站点运行情况字数不能超过2500字"); 
     return; 
    } 
    if(document.Form2.devRun.value.length>2500){ 

     alert("设备运行情况字数不能超过2500字"); 
     return; 
    } 
    */ 
    //alert('before...'); 
    document.Form2.action="${pageContext.request.contextPath}/system/elecCommonMsgAction_save.do"; 
    document.Form2.submit(); 
    alert(" 待办事宜保存成功!"); 
    } 

... 
<input type="button" name="BT_Submit" value="保存" onclick="checkchar()" id="BT_Submit" style="font-size:12px; color:black; height:20px;width:50px"> 

我不知道为什么我点击我的保存按钮,该法并没有执行,一些人可以帮我吗?如果是由上传样式表(http://localhost:8080/css/Font.css)引起的?我不确定。


编辑

由于主框架是frameset,以及JavaScript方法和输入按钮是在我的主网页(你可以看到下面的,这是红色的长方形我想补充)。因此,使用萤火虫它显示那里不包含任何JavaScript代码。

enter image description here


编辑-2

的我actingIndex.jsp所有代码:

<%@ page language="java" pageEncoding="UTF-8"%> 
<%--引入struts tags--%> 
<%@ taglib prefix="s" uri="/struts-tags" %> 


<html> 
<head> 
<title>运行监控模块编辑</title> 
<link href="${pageContext.request.contextPath }/css/Style.css" type="text/css" rel="stylesheet"> 
<link href="${pageContext.request.contextPath }/css/showText.css" type="text/css" rel="stylesheet"> 
<script language="javascript" src="${pageContext.request.contextPath }/script/function.js"></script> 
<script language="javascript" src="${pageContext.request.contextPath }/script/limitedTextarea.js"></script> 
<script language="javascript" src="${pageContext.request.contextPath }/script/showText.js"></script> 
<script src="${pageContext.request.contextPath}/ckeditor/ckeditor.js"/> 
<script src="${pageContext.request.contextPath}/ckfinder/ckfinder.js"/> 
<script type="text/javascript"> 
    function checkchar(){ 

     /* 
     if(document.Form2.stationRun.value.length>2500){ 

      alert("站点运行情况字数不能超过2500字"); 
      return; 
     } 
     if(document.Form2.devRun.value.length>2500){ 

      alert("设备运行情况字数不能超过2500字"); 
      return; 
     } 
     */ 
     alert('before...'); 
     document.Form2.action="${pageContext.request.contextPath}/system/elecCommonMsgAction_save.do"; 
     document.Form2.submit(); 
     alert(" 待办事宜保存成功!"); 
    } 
    function addEnter(element){ 
     document.getElementById(element).value = document.getElementById(element).value+"<br>"; 

    } 
    function checkTextAreaLen(){ 
     var stationRun = new Bs_LimitedTextarea('stationRun', 2500); 
     stationRun.infolineCssStyle = "font-family:arial; font-size:11px; color:gray;"; 
     stationRun.draw(); 

     var devRun = new Bs_LimitedTextarea('devRun', 2500); 
     devRun.infolineCssStyle = "font-family:arial; font-size:11px; color:gray;"; 
     devRun.draw(); 
    } 
    window.onload=function(){ 
     //checkTextAreaLen(); 
    } 
</script> 


</head> 

<body> 
<form name="Form1" id="Form1" method="post"> 
    <table cellSpacing="1" cellPadding="0" width="90%" align="center" bgColor="#f5fafe" border="0"> 
     <tbody> 
      <tr height=10><td></td></tr> 
      <tr> 
       <td> 
        <TABLE style="WIDTH: 105px; HEIGHT: 20px" border="0"> 
            <TR> 
             <TD align="center" background="${pageContext.request.contextPath }/images/cotNavGround.gif"><img src="${pageContext.request.contextPath }/images/yin.gif" width="15"></TD> 
             <TD class="DropShadow" background="${pageContext.request.contextPath }/images/cotNavGround.gif">运行监控列表</TD> 
            </TR> 
        </TABLE> 
        </td> 
      </tr> 
      <tr> 
       <td class="ta_01" align="center" bgColor="#f5fafe" colspan=3> 
         <table cellspacing="0" cellpadding="1" rules="all" bordercolor="gray" border="1" id="DataGrid1" 
          style="BORDER-RIGHT:gray 1px solid; BORDER-TOP:gray 1px solid; BORDER-LEFT:gray 1px solid; WIDTH:100%; WORD-BREAK:break-all; BORDER-BOTTOM:gray 1px solid; BORDER-COLLAPSE:collapse; BACKGROUND-COLOR:#f5fafe; WORD-WRAP:break-word"> 
          <tr style="FONT-WEIGHT:bold;FONT-SIZE:12pt;HEIGHT:25px;BACKGROUND-COLOR:#afd1f3"> 

           <td align="center" width="40%" height=22 background="${pageContext.request.contextPath }/images/tablehead.jpg">站点运行情况</td> 

           <td align="center" width="40%" height=22 background="${pageContext.request.contextPath }/images/tablehead.jpg">设备运行情况</td> 
           <td align="center" width="20%" height=22 background="${pageContext.request.contextPath }/images/tablehead.jpg">创建日期</td> 
          </tr> 
          <div id="showInfomation" style="visibility: hidden"></div> 
          <tr onmouseover="this.style.backgroundColor = 'white'" onmouseout="this.style.backgroundColor = '#F5FAFE';"> 
           <td style="HEIGHT:22px" align="center" width="40%"> 
            <div class="scrollStyle" align="left" onmouseover="showInfoWithPanel(this)" onmouseout="hiddenInfoPanel(this)" style="table-layout:fixed;"> 
             <s:property value="stationRun"/> 
            </div> 

           </td> 
           <td style="HEIGHT:22px" align="center" width="40%"> 
            <div class="scrollStyle" align="left" onmouseover="showInfoWithPanel(this)" onmouseout="hiddenInfoPanel(this)" style="table-layout:fixed;"> 
             <s:property value="devRun"/> 
            </div> 
           </td> 
           <td style="HEIGHT:22px" align="center" width="20%"> 
            <s:date name="createDate" format="yyyy-MM-dd HH:mm:ss" /> 
           </td> 
          </tr> 

         </table> 

        </td> 
       </tr> 

     </tbody> 
    </table> 
</form> 
<form name="Form2" id="Form2" method="post"> 
    <table cellspacing="1" cellpadding="5" width="90%" align="center" bgcolor="#f5fafe" style="border:1px solid #8ba7e3" border="0"> 

     <tr> 
      <td class="ta_01" colspan=2 align="center" background="${pageContext.request.contextPath }/images/b-info.gif"> 
      <font face="宋体" size="2"><strong>运行监控编辑</strong></font> 
      </td> 
     </tr> 
     <tr height=10><td></td><td></td></tr> 

     <tr> 
      <td class="ta_01" align="center" bgcolor="#f5fafe" width="15%">站点运行情况:</td> 
      <td class="ta_01" bgcolor="#ffffff" style="word-break: break-all"> 
       <s:textarea name="stationRun" id="stationRun" cssstyle="width: 1000px; height: 160px; padding: 1px;FONT-FAMILY: 宋体; FONT-SIZE: 9pt" onkeydown="if(event.keyCode==13)addEnter('stationRun');"></s:textarea> 
       <!--<script type="text/javascript"> 
        CKEDITOR.replace("stationRun", {height:200, width:800}); 
       </script>--> 

      </td> 

     </tr> 
     <tr> 
      <td class="ta_01" align="center" bgcolor="#f5fafe" width="15%">设备运行情况:</td> 
      <td class="ta_01" bgcolor="#ffffff" style="word-break: break-all"> 
       <s:textarea name="devRun" id="devRun" cssstyle="width:1000px; height: 160px; padding:1px;FONT-FAMILY: 宋体; FONT-SIZE: 9pt" onkeydown="if(event.keyCode==13)addEnter('devRun');"></s:textarea> 
       <!-- <script type="text/javascript"> 
        CKEDITOR.replace("devRun", {height:200, width:800}); 
       </script> --> 
      </td> 

     </tr> 
     <tr> 
      <td class="ta_01" style="width: 100%" align="center" bgcolor="#f5fafe" colspan="2"> 
      <input type="button" name="BT_Submit" value="保存" onclick="checkchar()" id="BT_Submit" style="font-size:12px; color:black; height:20px;width:50px">&nbsp;&nbsp; 
      <input style="font-size:12px; color:black; height:20px; width:80px" id="BT_Export" type="button" value="导出设置" name="BT_Export" 
         onclick="openWindow('${pageContext.request.contextPath }/system/exportExcel.jsp?belongTo=5-3','700','400')">&nbsp;&nbsp; 
      </td> 
     </tr> 
    </table> 
</form> 
</body> 
</html> 

回答

0

您打开脚本标签,但它不是关闭, 是在页面的END处插入脚本非常重要。所以页面 可以先注册控件。

function checkchar(){ 
 
     /* 
 
      if(document.Form2.stationRun.value.length>2500){ 
 

 
       alert("站点运行情况字数不能超过2500字"); 
 
       return; 
 
      } 
 
      if(document.Form2.devRun.value.length>2500){ 
 

 
       alert("设备运行情况字数不能超过2500字"); 
 
       return; 
 
      } 
 
      */ 
 
     //alert('before...'); 
 
     //document.Form2.action="${pageContext.request.contextPath}/system/elecCommonMsgAction_save.do"; 
 
     //document.Form2.submit(); 
 
     alert(" 待办事宜保存成功!"); 
 
    }
<input type="button" name="BT_Submit" value="保存" onclick="checkchar()" id="BT_Submit" style="font-size:12px; color:black; height:20px;width:50px">

+1

并不重要,在页面的年底建成时,代码只声明功能 – charlietfl

+0

@Mostafa Sabeghi我没有张贴的所有脚本方法在我的文章中,所以我没有复制结束脚本标记。 – 244boy

+0

@charlietfl是的,你是对的 –

0

试试这个checkchar()函数

function checkchar(){  
    alert("Hello"); 
}