JQuery UI datepicker在绑定到一个类时不起作用 [英] JQuery UI datepicker not working when bound to a class

查看:73
本文介绍了JQuery UI datepicker在绑定到一个类时不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码:

<html>
<head>
  <link type="text/css" href="css/blitzer/jquery-ui-1.7.2.custom.css" rel="stylesheet" />   
  <script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
  <script type="text/javascript" src="js/jquery-ui-1.7.2.custom.min.js"></script>
  <script type="text/javascript">
$(function() {
  $('.hasDatepicker').datepicker();
});
</script>
</head>
<body>
<p>date: <input type="text" name="data" class="hasDatepicker" /></p>
<input type="submit" value="send" />
</div>
</body>
</html>

当我点击输入字段时,没有任何反应。 DatePicker被初始化,当我检查Firebug中的DOM时,我得到 id =dp1260260566059添加到我的< input> 元素

When I click the input field, nothing happens. The datepicker is initialized though, when I inspect the DOM in Firebug, I get the id="dp1260260566059" added to my <input> element.

更改 html js 使用 id 属性而不是 class ,所以在我的代码中使用这个:

After changing the html and js to use id attribute instead of class, so having this in my code:

$(function() {
  $('#hasDatepicker').datepicker();
});

<p>date: <input type="text" name="data" id="hasDatepicker" /></p>

一切正常。

JQuery UI中的datepicker不能为某个类的所有元素工作吗?

Can't datepicker from JQuery UI work for all elements of some class?

推荐答案

如果您将输入字段的类名从hasDatePicker更改为其他内容,请检查datepicker是否有效。原因是,使用以下代码将datepicker添加到输入字段:

Please check if the datepicker works if you change the class name of the input fields from 'hasDatePicker' to something else. The reason is, when add the datepicker to the input field using the below code:

$(function() {
  $('#date').datepicker();
});

它将类名hasDatePicker添加到输入字段。 (这是你使用的一个)

it adds the class name "hasDatePicker" to the input field. (which is the one u r using)

这篇关于JQuery UI datepicker在绑定到一个类时不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆