PHP 中的下拉菜单
我在 SUN OS 服务器上使用 PHP 5.2。以下下拉菜单代码出现问题:
echo '<form action="" method="get">';
echo '<p>Information:<br />';
echo '<select name="acctno" style="width: 100px;">';
foreach ($this->account_names as $acctno => $acctname) {
echo '<option value="'.$acctno.'">'.$acctname.'</option>';
}
echo '</select> <input type="submit" value="view" />';
echo '</form>';
在 Firefox 和 Chrome 上工作得非常好;但是 Internet Explorer 存在问题。
在 IE 中,下拉菜单宽度限制为 100px。因此始终只显示帐户名的前 15-16 个字符。然而,在 Chrome 或 Firefox 中,即使最初只显示 15-16 个字符,当单击下拉箭头时,它也会显示整个名称(无论多长)。 IE 不会出现这种情况。因此,如果帐户名是“1223456789abcdefghijkl”,那么: 对于 IE:始终仅显示“123456789” F 对于 chrome 或 firefox:显示“123456789”,下拉时显示全名“123456789abcdefghijkl”。任何帮助将不胜感激。
谢谢, 副总裁
I am using PHP 5.2 on SUN OS server. Having problems with the following piece of code that for a drop down:
echo '<form action="" method="get">';
echo '<p>Information:<br />';
echo '<select name="acctno" style="width: 100px;">';
foreach ($this->account_names as $acctno => $acctname) {
echo '<option value="'.$acctno.'">'.$acctname.'</option>';
}
echo '</select> <input type="submit" value="view" />';
echo '</form>';
Worked perfectly fine on Firefox and Chrome; however there is a problem with Internet Explorer.
In IE the dropdown width is limited to the size i.e 100px. So only the first 15-16 characters of the account name are displayed all the time. However in chrome or firefox, even if only 15-16 characters are displayed initially, when the drop down arrow is clicked upon, it show the entire name (however long it may be). This does not happen with IE. So if the account name is, lets say, "1223456789abcdefghijkl" then:
For IE: shows only "123456789" all the time
Ffor chrome or firefox: shows "123456789" and when it is dropped down it show the full name as "123456789abcdefghijkl". Any help here would be much appreciated.
Thanks,
VP
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
这不是 PHP 问题,而是 CSS 问题。
因为我假设它正确地呈现了代码,并且这只在一个浏览器中被破坏,所以这是一个您必须诊断的浏览器特定错误。如果您发布网站链接或 CSS/HTML 输出,这将有助于我们为您提供帮助。
This isn't a PHP problem, it's a CSS problem.
Because I'm assuming it's rendering the code right, and this is only broken in one browser, it's a browser specific bug which you have to diagnose. If you post a link to the site or the CSS / HTML output that would help us help you.
这个问题与PHP无关,只与CSS和HTML有关。主要原因是标准(故意)没有准确指定下拉控件应如何工作。如果您查看标准,它甚至没有强制使用 根本没有下拉框。即使 HTML 5 标准草案也没有指定如何实现强制功能。如果浏览器实现者愿意,该标准允许控件在全屏 3D 立方体上显示所有选项,只要它允许选择一个选项即可。
如果您想精确控制下拉菜单的外观,则必须使用 JavaScript 创建一个下拉菜单并伪造其功能。
The problem has nothing to do with PHP, and only a bit with CSS and HTML. The main cause is that the standard (intentionally) does not specify exactly how drop-down controls should work. If you look at the standard, it doesn't even mandate the use of a dropdown box at all. Even the draft HTML 5 standard does not specify how the mandated functionality is to be implemented. The standard allows the control to show all options on a full-screen 3d cube if the browser implementer wants to, as long as it allows an option to be selected.
If you want precise control over what your dropdown looks like, you have to create one in javascript and fake the functionality.
这是IE浏览器的问题。它无法用 css 修复,但可以使用 javascript 修复它。
http://css-tricks.com/select-cuts -off-options-in-ie-fix/
This is an IE browser issue. It can't be fixed with css, but you can use javascript to fix it.
http://css-tricks.com/select-cuts-off-options-in-ie-fix/
这与 PHP 无关。下拉框的长度很可能是通过 CSS 处理的,并且两种浏览器都有自己的限制大小的方法。
That has nothing to do with PHP .. the length of the dropdown box is handled most probably with the CSS and both browsers have their own way of limiting the size.
这是 IE 中的已知错误/功能(并且有一个 重复的问题)。
在 IE 中,如果设置宽度,IE 会将其视为选择列表和所有选项的确切宽度,无论长度如何。
所有非IE浏览器都会意识到,当选择列表打开时,如果某些
option
大于指定的select
宽度,要加宽(unstylable)
下拉列表以适应,因为 CSS 无法控制它。由于非 IE 浏览器有一个可用的选择列表,我认为“他们的”版本是正确的。 IE 遵循请求的宽度,但当内容不适合时就不灵活。
在 IE7 或更高版本中,您可以在选项上设置
title="..."
属性,以便为截断的选项提供工具提示(请注意,在 IE6 中这不起作用)This is a known bug/feature in IE (and there is a duplicate SO question).
In IE if you set the width, IE takes that as the exact width for the select list and all options regardless of length.
All non-IE browsers realize that when the select list opens, if some of the
option
s are larger than the specifiedselect
width, to widen the(unstylable)
drop list to suit since CSS has no control over it.Since the non-IE browsers have a usable select list I take "their" version to be correct. IE's follows the requested width, but isn't flexible when the content doesn't fit.
In IE7 or above, you can set a
title="..."
attribute on the options so that a tooltip is provided for truncated options (note in IE6 this doesn't work)好吧,我有点懒 - 而且乐观 - 但是在 Firefox 和 Chrome 中测试过这一点,尽管只在 Ubuntu 9.10 上,理论 - 至少 - 是声音:
说实话,我怀疑它在 IE 上不起作用 - 否则会很容易 - 所以我想要么使用其他地方建议的
title
,或者也许 jQuery/js 来调整select
的宽度与其焦点上最宽/最长的子option
元素的宽度可能是最好的选择。编辑以添加上述实时演示的链接: http://davidrhysthomas.co.uk/so/select.html
而且,上帝啊,它也适用于 IE。尽管可能仅在 IE8 上,在 XP SP3 上具有 xhtml 1.0 严格文档类型。
Okay, I'm being a tad lazy -and optimistic- but having tested this in both Firefox and Chrome, albeit only on Ubuntu 9.10, the theory -at least- is sound:
To be honest I suspect it won't work on IE -otherwise it'd be easy- so I'm thinking that either using the
title
as suggested elsewhere, or perhaps jQuery/js to adjust the width of theselect
to its widest/longest childoption
element on focus, might be the best bet.Edited to add link to a live demo of the above: http://davidrhysthomas.co.uk/so/select.html
And, good lord, it works on IE too. Though perhaps only on IE8 with a xhtml 1.0 strict doctype on XP SP3.