我的struts jsp中不支持外部js

时间:2014-11-12 04:54:48

标签: java javascript jsp

![Uncaught ReferenceError: doClicks is not defined admin_page1:30][1]

我的jsp页面不支持 web - > js - > jquery-1.4.2.min.js 中的外部js文件。

此链接后的javascript方法doClicks()会导致错误:doClicks is not defined admin_page1:30][1]

相关代码:

        <script type="text/javascript" >
            function doClick(){
                alert("Hai");
            }
        </script>
        <script type="text/javascript" src="js/jquery-1.4.2.min.js"/>
        <script type="text/javascript">
            function doClicks(){
                alert("Hai");
            }

        </script>
<link rel="stylesheet" type="text/css" href="css/style.css" />
        <link rel="stylesheet" type="text/css" href="../css/style.css" />
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@taglib prefix="s" uri="/struts-tags"%> 
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Home page</title>

        
 </head>

    <body>
        <center>
            <input type="button" onclick="doClick()" value="Click sp"/>
            <input type="button" onclick="doClicks()" value="Click js"/>
            <table width="921" height="529" border="0">
                <tr>
                    <td height="143" colspan="2" id="header">&nbsp;</td>
                </tr>
                <tr>
                    <td height="37" colspan="2" id="link">
                        <center>
                            <div>
                                <a href="admin">Home</a>
                            </div>
                            <div>
                                <a href="admin_page1">Service1</a>
                            </div>
                            <div>
                                <a href="admin_page2">Service2</a>
                            </div>
                            <div>
                                <a href="out">Logout</a>
                            </div>
                        </center>
                    </td>
                </tr>
                <tr>
                    <td width="313" height="298" class="body"></td>
                    <td width="693" class="body">Service1</td>
                </tr>
                <tr>
                    <td height="33" colspan="2"><div align="center">copyright@2013</div></td>
                </tr>
            </table>
        </center>
    </body>
</html>

如何在jsp页面中添加外部js支持?

1 个答案:

答案 0 :(得分:0)

&#13;
&#13;
        <script type="text/javascript" >
            function doClick(){
                alert("Hai");
            }
        </script>
        <script type="text/javascript" src="js/jquery-1.4.2.min.js"/>
        <script type="text/javascript">
            function doClicks(){
                alert("Hai");
            }

        </script>
&#13;
<link rel="stylesheet" type="text/css" href="css/style.css" />
        <link rel="stylesheet" type="text/css" href="../css/style.css" />
&#13;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@taglib prefix="s" uri="/struts-tags"%> 
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Home page</title>

        
 </head>

    <body>
        <center>
            <input type="button" onclick="doClick()" value="Click sp"/>
            <input type="button" onclick="doClicks()" value="Click js"/>
            <table width="921" height="529" border="0">
                <tr>
                    <td height="143" colspan="2" id="header">&nbsp;</td>
                </tr>
                <tr>
                    <td height="37" colspan="2" id="link">
                        <center>
                            <div>
                                <a href="admin">Home</a>
                            </div>
                            <div>
                                <a href="admin_page1">Service1</a>
                            </div>
                            <div>
                                <a href="admin_page2">Service2</a>
                            </div>
                            <div>
                                <a href="out">Logout</a>
                            </div>
                        </center>
                    </td>
                </tr>
                <tr>
                    <td width="313" height="298" class="body"></td>
                    <td width="693" class="body">Service1</td>
                </tr>
                <tr>
                    <td height="33" colspan="2"><div align="center">copyright@2013</div></td>
                </tr>
            </table>
        </center>
    </body>
</html>
&#13;
&#13;
&#13;

&#13;
&#13;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@taglib prefix="s" uri="/struts-tags"%> 
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Home page</title>

        <link rel="stylesheet" type="text/css" href="css/style.css" />
        <link rel="stylesheet" type="text/css" href="../css/style.css" />



        <script type="text/javascript" >
            function doClick(){
                alert("Hai");
            }
        </script>
        <script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
        <script type="text/javascript">
            function doClicks(){
                alert("Hai js");

            }
            
            $().ready(function(){
                alert("ready");
            });
            
    
        </script>
    </head>

    <body>
        <center>
            <input type="button" onclick="doClick()" value="Click sp"/>
            <input type="button" onclick="doClicks()" value="Click js"/>
            <table width="921" height="529" border="0">
                <tr>
                    <td height="143" colspan="2" id="header">&nbsp;</td>
                </tr>
                <tr>
                    <td height="37" colspan="2" id="link">
                        <center>
                            <div>
                                <a href="admin">Home</a>
                            </div>
                            <div>
                                <a href="admin_page1">Service1</a>
                            </div>
                            <div>
                                <a href="admin_page2">Service2</a>
                            </div>
                            <div>
                                <a href="out">Logout</a>
                            </div>
                        </center>
                    </td>
                </tr>
                <tr>
                    <td width="313" height="298" class="body"></td>
                    <td width="693" class="body">Service1</td>
                </tr>
                <tr>
                    <td height="33" colspan="2"><div align="center">copyright@2013</div></td>
                </tr>
            </table>
        </center>
    </body>
</html>
&#13;
&#13;
&#13;

我使用此代码解决了上述问题