【问题标题】:In bootstrap modal width is always 0在引导模态宽度始终为 0
【发布时间】:2014-10-29 08:28:27
【问题描述】:

这是在jqgrid中加载完成的一个函数。

我有一个通过单击按钮打开的引导模式。在那个模式中,我有一个 jqgrid。当我在加载完成中调用一个函数时,在该函数中,附加跨度的宽度始终为0。您可以看到下面的函数:

function columnresize(id) { 

    $(this).parent().append('<span id="widthTest" />');

    gridName = this.id;

    $('#gbox_' + gridName + ' .ui-jqgrid-htable' + gridName).css('width', 'inherit');
    $('#' + gridName).parent().css('width', 'inherit');

    var columnNames = $("#" + gridName).jqGrid('getGridParam', 'colModel');
    var thisWidth;
    var itmCount = columnNames.length;
    /*var grid = $('#' + gridName);
    var iids = grid.getDataIDs();*/
    // Loop through Cols
    for (var itm = 0; itm < itmCount; itm++) {

    var curObj = $('[aria-describedby=' + gridName + '_' + columnNames[itm].name + ']');

    var thisCell = $('#' + gridName + '_' + columnNames[itm].name + ' div');
    $('#widthTest').html(thisCell.text()).css({
    'font-family': thisCell.css('font-family'),
    'font-size': thisCell.css('font-size'),
    'width': thisCell.css('width'),
    'font-weight': thisCell.css('font-weight')
    });


    var maxWidth = Width = $('#widthTest').width() + 17;
    //var maxWidth = 0;
    var itm2Count = curObj.length;
            // Loop through Rows
            for (var itm2 = 0; itm2 < itm2Count; itm2++) {

            var thisCell = $(curObj[itm2]);

            $('#widthTest').html(thisCell.html()).css({
            'font-family': thisCell.css('font-family'),
            'font-size': thisCell.css('font-size'),
            'font-weight': thisCell.css('font-weight')
            });

            thisWidth = $('#widthTest').width();
            if (thisWidth > maxWidth) {maxWidth = thisWidth+10;}
            }

    $('#' + gridName + ' .jqgfirstrow td:eq(' + itm + '), #' + gridName + '_' + columnNames[itm].name).width(maxWidth).css('min-width', maxWidth+17);
    $('#' + gridName + ' .jqgfirstrow td:eq(' + 0 + '), #' + gridName + '_' + columnNames[0].name).width('30').css('min-width', '30px');
    //grid.setRowData ( iids[itm], false, {height: 30} );

    }
    $('#widthTest').remove();
}

我在jqgrid的加载完成中这样调用上述函数:

loadComplete: function() {
columnresize.call(this, 'Table');
}

行内宽度$('#widthTest').width()

var maxWidth = Width = $('#widthTest').width() + 17;

始终为 0!

有什么想法吗?

【问题讨论】:

  • @Justinas 那么,如何获取隐藏的 DOM 元素的宽度?

标签: javascript jquery twitter-bootstrap jqgrid


【解决方案1】:

经过大量研究发现因为是隐藏的dom元素,所以不得不使用this

jquery 获取隐藏的 dom 元素的实际大小。

感谢@Justinas。

【讨论】:

    猜你喜欢
    • 2018-08-26
    • 2013-03-21
    • 2014-03-10
    • 1970-01-01
    • 2016-03-05
    • 1970-01-01
    • 2022-01-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多