jquery - 增加从 jquery 生成的字段的大小

标签 jquery html css

以下标签:

<input type="text" class="timepicker" name="SelectedTime" id="timepicker"  />

jquery 的帮助下:

/* jQuery timepicker
 * replaces a single text input with a set of pulldowns to select hour, minute, and am/pm
 *
 * Copyright (c) 2007 Jason Huck/Core Five Creative (http://www.corefive.com/)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *
 * Version 1.0
 */

(function($){
    jQuery.fn.timepicker = function(){
        this.each(function(){
            // get the ID and value of the current element
            var i = this.id;
            var v = $(this).val();

            // the options we need to generate
            var hrs = new Array('01','02','03','04','05','06','07','08','09','10','11','12');
            var mins = new Array('00','15','30','45');
            var ap = new Array('am','pm');

            // default to the current time
            var d = new Date;
            var h = d.getHours();
            var m = d.getMinutes();
            var p = (h >= 12 ? 'pm' : 'am');

            // adjust hour to 12-hour format
            if(h > 12) h = h - 12;

            // round minutes to nearest quarter hour
            for(mn in mins){
                if(m <= parseInt(mins[mn])){
                    m = parseInt(mins[mn]);
                    break;
                }
            }

            // increment hour if we push minutes to next 00
            if(m > 45){
                m = 0;

                switch(h){
                    case(11):
                        h += 1;
                        p = (p == 'am' ? 'pm' : 'am');
                        break;

                    case(12):
                        h = 1;
                        break;

                    default:
                        h += 1;
                        break;
                }
            }

            // override with current values if applicable
            if(v.length == 7){
                h = parseInt(v.substr(0,2));
                m = parseInt(v.substr(3,2));
                p = v.substr(5);
            }

            // build the new DOM objects
            var output = '';

            output += '<select id="h_' + i + '" class="h timepicker">';             
            for(hr in hrs){
                output += '<option value="' + hrs[hr] + '"';
                if(parseInt(hrs[hr]) == h) output += ' selected';
                output += '>' + hrs[hr] + '</option>';
            }
            output += '</select>';

            output += '<select id="m_' + i + '" class="m timepicker">';             
            for(mn in mins){
                output += '<option value="' + mins[mn] + '"';
                if(parseInt(mins[mn]) == m) output += ' selected';
                output += '>' + mins[mn] + '</option>';
            }
            output += '</select>';              

            output += '<select id="p_' + i + '" class="p timepicker">';             
            for(pp in ap){
                output += '<option value="' + ap[pp] + '"';
                if(ap[pp] == p) output += ' selected';
                output += '>' + ap[pp] + '</option>';
            }
            output += '</select>';              

            // hide original input and append new replacement inputs
            $(this).attr('type','hidden').after(output);
        });

        $('select.timepicker').change(function(){
            var i = this.id.substr(2);
            var h = $('#h_' + i).val();
            var m = $('#m_' + i).val();
            var p = $('#p_' + i).val();
            var v = h + ':' + m + p;
            $('#' + i).val(v);
        });

        return this;
    };
})(jQuery);

$(document).ready(function() {
   $('.timepicker').timepicker();
});


/* SVN: $Id: jquery.timepicker.js 456 2007-07-16 19:09:57Z Jason Huck $ */

给出:

enter image description here

如何增加输入字段的大小?我试过这样做:

<input type="text" class="timepicker" name="SelectedTime" 
   id="timepicker" style="height:40px; font-size:20px"  />

但输出是一样的。

最佳答案

您的 jQuery 代码隐藏了实际的输入字段并将它们替换为 select,类名称为“timepicker”,您可以使用它来控制样式。

在您的代码中应用以下 css:

.timepicker{
    height: 40px;
    font-size: 20px;
}

关于jquery - 增加从 jquery 生成的字段的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23180894/

相关文章:

jquery - 检测屏幕大小并更改 div 填充中的百分比

jquery - 为什么Select2框架找不到一些unicode字符?

jquery - .on() .off() 之后的 jQuery 事件

javascript - slideToggle() 动画期间出现跨文本换行问题

页面底部的 CSS 页脚

javascript - window.location 之后如何存储数据?

jquery - 如何使用 knockout.js 将项目列表与 dropdownlist 绑定(bind)

javascript - 如何只选择具有特定 CSS 类的节点? D3/JS

javascript - 如何创建一个带有提交按钮的文本框,该按钮在单击时使用 js 或 jQuery 执行回调到 javascript 函数?

html - 使用 CSS 从 div 顶部开始循环 "cut-away"