jquery ui selectmenu:如何正确设置动态宽度?
我想使用来自 felixnagel 的 jquery ui selectmenu。它有效,但我有一个问题,jquery 总是为选择菜单设置太小的宽度,以便打开/关闭图标出现在内容上方。我知道我可以在命令 selectmenu() 中设置宽度,但我有几个不同的选择菜单,所以我想知道我可以在哪里影响正确计算选择菜单的宽度,以便我可以给出它是一个额外的 px 宽度。
我试图在 .js 文件中找到它,但从现在起我没有成功找到它。希望你们中有人知道我在这里能做什么。
i would like to use jquery ui selectmenu from felixnagel. it works but i have the problem that jquery always set a too small width for the selectmenu so that the open/close icon appears above the content. I know that i can set the width in the command selectmenu() but i have a couple of different selectmenus, so i would like to know where i can take influence on the correct calculation how wide the selectmenu will be, so that i can give it an additional px for the width.
I tried to find it in the .js files, but since now i was not successfull with it. Hopefully someone of you have an idea what i can do here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这很简单,并且可以根据内容进行调整。
这使用硬编码宽度来避免选择评论中提到的不同宽度的项目时出现的问题:
This is simple and makes it adjust based on content.
This uses a hard coded width to avoid the problem when selecting items of different widths mentioned in the comment:
也许这样的东西会帮助你
你遍历每个选择元素,你将有可能在选择元素宽度属性中指定 with 。也许您发现它很有用并且可以对其进行修改以满足您的需求。
编辑1:
或者,如果你只是想通过代码添加一些额外的东西(我认为你也可以使用 CSS 来做到这一点),你可以使用类似的东西:
Maybe something like this will help you
You walk thru every select element and you will have the possibilty to specify the with in the select elements width attribute. Maybe you find it useful and can modify it so it fill your needs.
Edit 1:
Or if you just want to add something extra thru code (I think you can do it also with CSS) you could use something like:
这是一种黑客,我不知道它有多强大,但我已经在一个特定的实例中成功地使用了它:
简而言之,它的作用是:
,只是它在很大程度上依赖于 jquery-ui 内部的处理方式,因此它可能会在任何更新时中断。
请参阅此小提琴:http://jsfiddle.net/txo1mvhn/2/
It's kind of a hack and I don't know how robust this is but I've successfully used this in one particular instance:
In a nutshell what it does is:
It's just that it kind of heavily relies on how jquery-ui does things internally so it might break upon any update.
See this fiddle: http://jsfiddle.net/txo1mvhn/2/
以前的解决方案几乎是正确的。
您必须设置 css 宽度并调用 selectmenu ,如下所示:
Previous solutions were almost right.
You have to set css width and call selectmenu like this:
对于百分比,如下所示:
在 CSS 中声明百分比:
在 JavaScript 中声明:
For percentages, is like this:
Declare the percentage in your CSS:
And in your JavaScript: