ds342222 2015-10-21 17:23
浏览 47
已采纳

循环或通配符通过JQuery UI Javascript集成

I am calling the content of a PHP file via AJAX similar to this:

NEW.PHP

$output =  '<p>Date: <input type="text" id="field_1"></p>
            <p>Date: <input type="text" id="field_6"></p>
            <p>Date: <input type="text" id="field_7"></p>';

echo $output;

The inputs are generated dynamically depending on options the user selected. In this case, field_1 and field_7 would be date picker fields and field_6 would be a standard text box.

In my main page, the jQuery success handler looks like this:

success: function(result){
    jQuery('#div-custom').html(result).show();                
    jQuery("#div-custom").find("#field_1,#field_7" ).datepicker({
              numberOfMonths: 3,
              showButtonPanel: true
    });
}

The issue I'm having is that the number of date picker fields is dynamic and the field number field_X can be different. Is there a way to make this find("#field_1,#field_7") dynamic or use a wildcard? I can change my PHP code so that, for example, all date picker fields are called date_X and other fields are field_X.

In that case, I'd like to do something like find("#date_*) but don't know if that's possible. I'm definitely not strong with Javascript.

Really appreciate any help!

  • 写回答

2条回答 默认 最新

  • dotelauv682684 2015-10-21 17:30
    关注

    You should use a class as you can use the same class on multiple items unlike ids

    <p>Date: <input type="text" class="cal" id="field_X"></p>

    jQuery("#div-custom").find(".cal" ).datepicker({

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊