在 JSP 中使用 jQuery Datepicker

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13709197/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 12:53:05  来源:igfitidea点击:

Using jQuery Datepicker in a JSP

jqueryjsp

提问by

Below is the jsp code.

下面是jsp代码。

<head>
    <link rel="stylesheet" type="text/css" href="<%=contextPath %>/style_sheet/page_header.css" >
    <link href="<%=contextPath %>/scripts/jQuery/jquery-ui.css" rel="stylesheet" type="text/css"/>
    <script  src="<%=contextPath %>/scripts/jQuery/jquery.min.js" ></script>
    <script  src="<%=contextPath %>/scripts/jQuery/jquery-ui.min.js"></script>
    <script src="jscript.js" ></script>

    <style>
        .pageWidth
        {
            width: 800px;
        }
    </style>

    <script>
        $(document).ready(function(){
            $("#startDatePicker").datepicker();
        });
    </script>

    <title>GFW Voice OUT Files Trend</title>


</head>
<body>

      <table width="800x" border="0" align="center">
         <tr>
            <td>Start Date: <input type="text" id="startDatePicker" /></td>
         </tr>
      </table>

</body> 

I get an error at the syntax

我收到语法错误

$(document).ready(function(){
   $("#startDatePicker").datepicker();
});

Error

错误

The function $(HTMLDocument) is undefined.

I though eclipse is getting confused between EL and jQuery syntax, but using \$ did not help. what am I doing wrong? All I want to do is use jQuery datepicker.

我虽然 Eclipse 对 EL 和 jQuery 语法感到困惑,但使用 \$ 并没有帮助。我究竟做错了什么?我想要做的就是使用 jQuery 日期选择器。

回答by saitakyuz

jquery file is not installed correctly. Use that code its work.

jquery 文件未正确安装。使用该代码的工作。

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"      "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

 <link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" />
  <script src="http://code.jquery.com/jquery-1.8.3.js"></script>
  <script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
  <script>
$(function() {
    $( "#datepicker" ).datepicker();
});
</script>
 <title>Test</title>
</head>
<body>

Date: <input type="text" id="datepicker" />
</body>
  </html>

回答by Vaishak Suresh

Use noConflictto resolve the conflict.

使用noConflict解决冲突。

回答by Jai

try some of these:

尝试其中一些:

<table width="800x" border="0" align="center">
           //----^-----------------remove the x here no need of it

and

jQuery(document).ready(function($){
   $("#startDatePicker").datepicker();
});