Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/475.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 输入按钮onclick在JSP中不起作用_Javascript_Java_Jsp_Input - Fatal编程技术网

Javascript 输入按钮onclick在JSP中不起作用

Javascript 输入按钮onclick在JSP中不起作用,javascript,java,jsp,input,Javascript,Java,Jsp,Input,我在Firefox中测试我的问题。我点击保存按钮(它是一个输入,类型是按钮),它应该执行: onclick="checkchar()" 但事实并非如此 我在jsp中的代码部分: <script language="javascript"> function checkchar(){ /* if(document.Form2.stationRun.value.length>2500){ alert("站点运行情况字数不能超过2500字");

我在Firefox中测试我的问题。我点击保存按钮(它是一个输入,类型是
按钮
),它应该执行:

onclick="checkchar()"
但事实并非如此

我在
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">
<%@ 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>

您打开了脚本标记,但它没有关闭,并且 在页面末尾插入脚本非常重要。这样页面 可以先注册控件

函数checkchar(){
/*
if(document.Form2.stationRun.value.length>2500){
警报(“站点运行情况字数不能超过2500字");
返回;
}
if(文件格式2.devRun.value.length>2500){
警报(“设备运行情况字数不能超过2500字");
返回;
}
*/
//警惕(‘在……之前’);
//document.Form2.action=“${pageContext.request.contextPath}/system/elecCommonMsgAction_save.do”;
//文件。表格2。提交();
警报(“待办事宜保存成功!");
}
试试这个checkchar()函数


当代码只声明functions@MostafaSabeghi我没有在我的帖子中发布所有的script方法,所以我没有复制其中的end script标记。@244boy用firebug检查你的代码,该方法已经执行,我猜你的脚本中有javascript错误code@MostafaSabeghi如何检查javascript中是否存在错误代码?我使用IntelliJ IDEA。@MostafaSabeghi卸载的
css
不会导致这种类型的问题,好吗
 function checkchar(){    
    alert("Hello");
 }