简体   繁体   English

元素选择器内的jQuery变量

[英]jQuery variable inside element selector

I am making a datepicker using jQuery, i retrieve the input id's for the inputs that need a datepicker through user input.我正在使用 jQuery 制作日期选择器,我通过用户输入检索需要日期选择器的输入的输入 ID。 Those id's are stored in an array that loops through an foreach .这些 id 存储在一个循环遍历foreacharray中。

Now i want to pass those id's inside the element selector to add the right attributes, currently I am using variables for that but i doubt that this is a valid way for doing this,现在我想在元素选择器中传递这些 id 以添加正确的属性,目前我正在为此使用变量,但我怀疑这是执行此操作的有效方法,

Any help is appreciated :)任何帮助表示赞赏:)

 foreach ($date_picker_input_id as $input_id) 
    {
        if (!$('input[id='$input_id']').val()) 
        {
           $('input[id='$input_id']').val('<?= date('d-m-Y'); ?>');
           $('input[id='$input_id']').datepicker(datepicker_settings);
        }
    }

You are missing php tags :您缺少 php 标签:

try this :尝试这个 :

   <script type="text/javascript">
        <script type="text/javascript">
        $(document).ready(function()
        {
            $.datepicker.setDefaults($.datepicker.regional['int']);
            $.datepicker.setDefaults({
            showOn: 'both',
            buttonImageOnly: true,
            buttonImage: "<?= $url_icon_calendar; ?>",
            buttonText: "[:datepicker_title:]"
            });

          var datepicker_settings = { dateFormat: 'dd-mm-yy' };
          <?php
          foreach ($date_picker_input_id as $input_id) 
          {
              if (!$('input[id='$input_id']').val()) {
          ?>
              $('input[id='$input_id']').val('<?= date('d-m-Y'); ?>');
          <?php } ?>
              $('input[id='$input_id']').datepicker(datepicker_settings);
              $('input[id='$input_id']').css({'float': 'left', 'width': '50%'});

              $('img.ui-datepicker-trigger').css({
              'width': '22px', 'height': '22px', 'float': 'left', 'position':'relative','left':'-24px','top':'-1px', 'opacity':'0.8'});
          <?php } ?>
        });
    </script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM