dongxixian7803 2016-07-23 13:56
浏览 24

在输入字段中查找和替换文本

I have a joomla registration form (using the easyprofile joomla component) with a date field (calendar date picker) which put the date in the following format:

31-12-2016

Id like to change the format of this date to:

31-Dec-2016

I wondered if this is possible with php or even js to find and replace the string in this field, something like the following:

FIND: -01- REPLACE: -Jan-

FIND: -02- REPLACE: -Feb-

This would have to work instantly as soon as the user selects or changes the date from the calendar.

Many thanks in advance is anyone can help!

  • 写回答

1条回答 默认 最新

  • duandong2562 2016-07-23 17:10
    关注

    Try the following:

    Split the string, find the month by index, recreate the date and add as value.

    [JQUERY]

    var months = ['Jan','Feb','May','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
    
    // You can also use the classname or id to select the element.
    // var element = $('.classname');
    var element = $('input[name="jform[moving_date]"]');
    
    element.on('change', function(e) {
    
        // You might need to stop propagation but this will cause other scripts from firing like date picker.
        // e.stopPropagation();
    
        var date_parts = $(this).val().split('-');
        var month_index = Number(date_parts[1]) - 1;
        var date_new = date_parts[0] + '-' + months[month_index] + '-' + date_parts[2];
        $(this).val(date_new);
    }); 
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器