jquery - 如何限制下拉列表的宽度

标签 jquery html css asp.net-mvc-4

我有一个包含一些下拉列表的 html 表格。

<table>
    <thead>
        <tr>
            <th>@Html.LabelFor(model => model.WorkorderId)</th>
            <th>@Html.LabelFor(model => model.SubmissionDate)</th>
            <th>@Html.LabelFor(model => model.PartId)</th>
            <th>@Html.LabelFor(model => model.ActivityId)</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>@Html.DropDownList("WorkorderId", (SelectList) ViewBag.Workorders, string.Empty)</td>
            <td>@Html.TextBoxFor(model => model.SubmissionDate, "{0:MM/dd/yyyy}", new { @class = "datefield" })</td>
            <td>@Html.DropDownList("PartId", (SelectList) ViewBag.Parts, string.Empty)</td>
            <td>@Html.DropDownList("ActivityId", (SelectList) ViewBag.Activities, string.Empty)</td>
        </tr>
    </tbody>
</table>

其中一列(The PartId column),有很长的描述。它几乎占据了整个页面。

12345 - The very long description for Part

我想将下拉列表的宽度限制为与 PartNumber 一样长(没有描述)。现在,下拉列表的宽度等于 PartNumer - Description 中最长的一个。

有没有一种方法可以在选择零件编号 (12345) 时只显示零件编号 (12345),但在单击下拉菜单时显示整个零件(编号 - 描述)?

最佳答案

将下拉列表的宽度限制为 150px :

 @Html.DropDownList("WorkorderId", (SelectList) ViewBag.Workorders, new { @style = "max-width:150px;" }

关于jquery - 如何限制下拉列表的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37979797/

相关文章:

jquery - 如果 .next() 元素是 .last() 元素?

javascript - 使用 document.getElementsByName 选择数组中的多个选项

html - 更改窗口大小时文本超出 div 的边框

html - 绝对/相对定位问题

jquery - 我需要能够打印页面的一部分,但也需要保持打印整个页面的能力

jquery - 如何让 Photoswipe 从缩略图列表中识别整个图库

javascript - 与调用 JQuery 自定义函数感到困惑

python - 存储模型的django表单下拉列表

html - 如何在页面中心对齐列?

javascript - AJAX 表单发送 GET 并将表单发送到当前页面而不是 POST jquery