I've got a jQuery date picker control that works fine for once instance, but I'm not sure how to get it to work for multiple instances.

我有一个jQuery日期选择器控件,它只对一个实例有效,但我不确定如何让它在多个实例中工作。

<script type="text/javascript">
    $(function() {
        $('#my_date').datepicker();
    });
</script>

<% Using Html.BeginForm()%>
<% For Each item In Model.MyRecords%>
<%=Html.TextBox("my_date")%> <br/>
<% Next%>
<% End Using%>

Without the For Each loop, it works fine, but if there's more than one item in the "MyRecords" collection, then only the first text box gets a date picker (which makes sense since it's tied to the ID). I tried assigning a class to the text box and specifying:

没有For每个循环,它可以正常工作,但是如果“MyRecords”集合中有多个项,那么只有第一个文本框获得一个日期选择器(这是有意义的,因为它与ID绑定)。我尝试给文本框分配一个类并指定:

$('.my_class').datepicker();

but while that shows a date picker everywhere, they all update the first text box.

但是,尽管在每个地方都显示一个日期选择器,它们都更新第一个文本框。

What is the right way to make this work?

怎样做才是正确的方法呢?

12 个解决方案

#1


112

html:

html:

<input type="text" class="datepick" id="date_1" />
<input type="text" class="datepick" id="date_2" />
<input type="text" class="datepick" id="date_3" />

script:

脚本:

$('.datepick').each(function(){
    $(this).datepicker();
});

(pseudo coded up a bit to keep it simpler)

(伪代码稍微简化了一点)

更多相关文章

  1. 输入类型=日期的日期显示为dd-mm-yyyy格式
  2. 利用javascript实现遍历xml文件的代码实例
  3. 我可以使用onBlur事件对TextBox进行日期检查吗?
  4. Day.js :一个轻量的处理时间和日期的 JavaScript 库
  5. 使用Isotop过滤日期
  6. 如何使用Require JS配置具有第三方js依赖项的日期选择器?
  7. 第三节(JavaScript 对象、日期,函数)
  8. javascript适合移动端的响应式瀑布流插件实例演示
  9. Net.Socket实例不会在NodeJS中消失

随机推荐

  1. Android 使用 Gmail 来发送邮件
  2. android notification实例
  3. android 日期时间格式转换;软键盘显示消失
  4. AIDL使用
  5. Android使用百度地图移动到我的位置
  6. android recovery 和reboot
  7. Android的Bluetooth Profile与UUID
  8. Android添加垂直滚动ScrollView
  9. android 圆角图标 和不规则圆角(边框)
  10. [Android Pro] PackageManager#getPackag