简体   繁体   English

如何在选择框中限制选项名称的大小?

[英]How to Limit the size of the option name in the select box?

I am retrieving the options of the select box from the database. 我正在从数据库中检索选择框的选项。 I want to limit the width of the option value in the drop down box. 我想在下拉框中限制选项值的宽度。

Eg: The value in the data base is "ELEPHANT GROUP" In my drop down if i need only 8 characters long. 例如:如果我只需要8个字符长,则数据库中的值为“ ELEPHANT GROUP”。 The value to be displayed in the dropdown box is "ELEPHANT" 下拉框中显示的值为“大象”

I want my option values to be limited to a particular size. 我希望将选项值限制为特定大小。 Can any one help me in resolving this issue.? 任何人都可以帮助我解决这个问题。

Brief Info: 简要信息:

My developer has a dynamic list box on one of his forms. 我的开发人员在其表单之一上有一个动态列表框。 ie: The Administrative user can create options which display in a Select Box for the General User to choose from. 即:管理用户可以创建显示在选择框中的选项,供普通用户选择。 Our intention was for the Admin User to create options of about 50 characters max, but our business requirements do not allow us to restrict the size of the Option Name the Admin User creates. 我们的目的是让管理员用户创建最多约50个字符的选项,但是我们的业务要求不允许我们限制管理员用户创建的选项名称的大小。 This leaves us open to the possibility of a SelectBox that is hundreds of characters wide, throwing all table formatting out the window and causing the screen to scroll horizontally. 这使我们有可能选择几百个字符宽的SelectBox,从而将所有表格都格式化为窗口,并导致屏幕水平滚动。 We've been arguing about this endlessly for days now, and apparently CANNOT limit the character input for the Option Name. 几天来我们一直在为此争论不休,并且显然不能限制“选项名称”的字符输入。 Is there any way to manipulate the display of the Select Box to prevent it from exceeding a certain number of characters wide but still show very long Option Names? 有什么方法可以操纵选择框的显示,以防止选择框超出一定数量的字符,但仍显示很长的选项名称?

Hope now u have got my problem exactly.. Please help me in resolving it. 希望现在您已经完全解决了我的问题。请帮助我解决问题。

Thank you... 谢谢...

您可以执行substring()以获取要显示的8个首字符

enter code here

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>

<BODY>

<select id = "mysel" onchange = "show()">
<option value = 0>Select one ....</option>
<option value = "January">January</option>
<option value = "February">February</option>
<option value = "March">March</option>
</select>
<br>
<input type = "text" id = "month" size = "1" readonly>

<script type = "text/javascript">

function show() {
var val = document.getElementById("mysel").value;
val = val.substring(0,3);
alert (val);
document.getElementById("month").value = val;
}

</script>
</BODY>
</HTML>

/ By using the substring u can do it.Else you can specify the width of a box with style with the newer browsers that support CSS. / 通过使用子字符串,您可以做到。否则,您可以使用支持CSS的新型浏览器指定具有样式的框的宽度。 The only problem is, you can not see the whole word. 唯一的问题是,您看不到整个单词。 It cuts it off. 它切断了它。 hope that helps you out / 希望可以帮助您 /

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

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