简体   繁体   English

为什么表格多于5行需要两次点击?

[英]Why table require two clicks when it has more than 5 row?

I have the problem. 我有问题。 I have a page with dropdown menu that contain customers name and if customer name is selected appear table with customer configuration. 我有一个带有下拉菜单的页面,其中包含客户名称,如果选择了客户名称,则显示带有客户配置的表。 在此处输入图片说明

Customer can choose row in the table use one click on left mouse button: 客户可以使用鼠标左键单击表中的行: 在此处输入图片说明

When table has more than 5 rows it's style is changed (There is restriction display no more than five rows). 当表格的行数超过5行时,样式会更改(限制显示的行数不能超过5行)。 在此处输入图片说明 And if we press left mouse button in the first time on any field of page, table style is changed (also dropdown menu is unfocused): 而且,如果我们在页面的任何字段上第一次按下鼠标左键,表格样式都会更改(下拉菜单也没有重点显示): 在此处输入图片说明 And it's necessary press left button of the mouse in the second time for select configuration. 并且需要第二次按下鼠标左键进行选择配置。 It is happened only when table has more than five rows. 仅当表具有多于五行时才发生。 (Table is built by jquery). (表由jquery构建)。

Code: 码:

function changeCustomerName(customerName) {
        getConfigurationsForSpecifiedCustomer(customerName);
    }

function createTableForConfiguration(data){
    fillTable(data);
    $('#configurationTable').show();
}

function fillTable(data){
    $('#tableBody').empty();
    data.forEach(function(item) {
        $('#tableBody').append(
            '<tr>' +
            '<td style="display:none">' +
            item.id +
            '</td>' +
            '<td>' +
            item.name +
            '</td>' +
            '</tr>'
        )
    });
}

function getConfigurationsForSpecifiedCustomer(customerName) {
    $.ajax({
        type: "POST",
        contentType: "application/json",
        url: "/getConfigurationsForSpecifiedCustomer",
        data: JSON.stringify(customerName),
        dataType: 'json',
        success: function(response) {
            createTableForConfiguration(response);
        },
        error: function(e){
            // alert('Error from getConfigurationsForSpecifiedCustomer' + e);
            console.log('Error from getConfigurationsForSpecifiedCustomer' + e);
            $('#configurationTable').hide();
        }
    });
}

$(document).ready(function(){

    $('#secondTable').on("click", '#tableBody tr', function(){
        var selected = $(this).hasClass("highlight");
        $("#tableBody tr").removeClass("highlight");
        if(!selected)
            $(this).addClass("highlight");
        $("[name='configuration']").val($(this).context.children[0].innerText);
    });
});

html: 的HTML:

 <div id="table" class="scroll">
                <table id="secondTable" class ="tableBorder">
                    <thead>
                    <tr>
                        <th style="display:none">id</th>
                        <th>Configuration Name</th>
                        <th>Product Name</th>
                        <th>Product Version</th>
                        <th>Solution Build</th>
                        <th>Customer Name</th>
                        <th>GP Code</th>
                        <th>Oracle DB Version</th>
                        <th>Configuration Version</th>
                    </tr>
                    </thead>
                    <tbody id="tableBody">
                    </tbody>
                </table>
            </div>

style: 样式:

    body {
    font-size: 1em;
}

h1 {
    font-size: 2em;
}

table.tableBorder {
    width: 100%;
    border: 1px solid black;
    border-collapse: collapse;
}

table.tableBorder th, table.tableBorder td {
    padding: 4px 3px;
    border: 1px solid black;
}

.scroll{
    width: 100%;
    max-height: 150px;
    overflow: auto;
}

.highlight { background-color: grey; }

response of ajax call: ajax调用的响应: 在此处输入图片说明 What a reason can be? 是什么原因呢?

滚动类中必须增加宽度。

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

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