繁体   English   中英

jQuery datepicker无法在内部工作<h:form>

[英]jquery datepicker not working inside <h:form>

我从https://jqueryui.com/datepicker/获得了datepicker代码

源代码按此方式工作,但在我的jsp内的标签内却不起作用(不弹出日历)。 如果将输入文本放置在h:form之外,则源工作正常(弹出日历已到)。 我正在使用eclipse和jsf开发页面
这是代码:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="f"  uri="http://java.sun.com/jsf/core"%>
<%@ taglib prefix="h"  uri="http://java.sun.com/jsf/html"%>
<!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=ISO-8859-1">
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
  <script src="http://code.jquery.com/jquery-1.10.2.js"></script>
  <script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
  <script>
  $(function() {
    $( "#datepicker" ).datepicker();
  });
  </script>

<title>Insert title here</title>
</head>
<body>
<f:view>
<h:form>
<h:outputText value="Select date" />
<h:inputText id="datepicker"/>
</h:form>
</f:view>
</body>
</html>

尝试在Firebug或开发人员控制台中查看datepicker的真实ID。 JSF将表单的ID添加到元素中,例如“ formID:datepicker”,因此,如果执行$('#datepicker'),则jquery无法找到它。

代码还可以,但是您缺少样式部分

  <link rel="stylesheet" href="/resources/demos/style.css">

你没有。 在我的电脑上,它可以工作,但是由于缺少CSS,因此无法正确设置样式。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM