2017-04-09 36 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"); 
}