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条)

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站