duanfengshang1088 2017-08-11 03:41
浏览 62
已采纳

Wordpress上的jQuery TimeEntry

I have a Time range field I am trying to implement into my Wordpress page. Where do I need to put this code and how do I call it when I want the range text box displayed on my page?

$('.timeRange').timeEntry({beforeShow: customRange}); 


function customRange(input) { 
    return {minTime: (input.id === 'timeTo' ? 
        $('#timeFrom').timeEntry('getTime') : null),  
        maxTime: (input.id === 'timeFrom' ? 
        $('#timeTo').timeEntry('getTime') : null)}; 
}

I have this for just a simple Time Entry field.

<script>
    $.timeEntry.setDefaults({spinnerImage: 'http://sdtest.net/wp-content/uploads/2017/06/spinnerDefault.png'});
    </script>
    <script>
    $(function () {
        $('#timeEntry').timeEntry({defaultTime: +20});
    });
</script>

and I call it with this html

<input type="text" id="timeEntry">

Just need help getting the ranged textbox script put in the right place and the correct code to call it.

Any help would be greatly appreciated.

Thanks, Matt

  • 写回答

1条回答 默认 最新

  • doushou8730 2017-08-11 04:06
    关注

    I think it should look like this:

    <script>
    
    $.timeEntry.setDefaults({spinnerImage: 'http://sdtest.net/wp-content/uploads/2017/06/spinnerDefault.png'});
    
    function customRange(input) { 
      return {
        minTime: (input.id === 'timeTo' ? $('#timeFrom').timeEntry('getTime') : null),  
          maxTime: (input.id === 'timeFrom' ? $('#timeTo').timeEntry('getTime') : null)
      }; 
    }
    
    $(function () {   // This is a "document ready" wrapper
    
      $('#timeEntry').timeEntry({defaultTime: +20});      
      $('.timeRange').timeEntry({beforeShow: customRange});
    
    });
    </script>
    

    There is no need to have multiple <script> and </script> tags like in what you posted. Those are tags to contain code.

    $(function () { is a "document ready" wrapper.
    It's the shorthand way to write $(document).ready(function(){

    What is inside will only be executed when the DOM (Document Object Model) is fully loaded (So when all elements are loaded), instead of beeing executed on parsing.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于logstash转发日志时发生的部分内容丢失问题
  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?