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

报告相同问题?

悬赏问题

  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败