【发布时间】:2019-09-21 02:14:58
【问题描述】:
我有一个有趣的问题。我有一个用于选择的按钮(如选择项)。代码在这里:
<button class="btn btn-primary dropdown-toggle" style="width: 166%;"
type="button" id="dropdownMenuButton" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">
<span id="dropdown_button" style="width: 166%;">
<img src="wp-content/themes/directory2/images/closest.png" />
10 Closest Amenities</span>
<span class="caret" style="margin-top: 9px;float: right;"></span>
</button>
然后它使用一些 jquery 来更改按钮/选择中的文本,如下所示:
$(document).on('click', '.dropdown_anchor', function(event) {
var index = $(this).data('index');
var title = $(this).data('title');
populate_list(index);
dropdownButtonText(title);
});
那么dropdownButtonText函数实现如下:
function dropdownButtonText(text) {
$("#dropdown_button").text(text);
}
The problem is, that the button spans the width it needs to on page load (aka style="width: 166%;") but when the selection happens and its changed, the button then doesn't hold its set width.例如,它的含义是从 166% 到 87% 宽度。
如何使按钮在更改时保持其宽度?
感谢您的投入和时间,非常感谢。
可以在这里看到一个例子: https://www.trustedlivingcare.com/item/cedarhurst-of-sparta-il/
社区和附近的便利设施区
【问题讨论】:
-
你能做一个sn-p来演示这个问题吗?更改文本不会更改宽度除非原始文本比允许的宽度更宽并且它强制元素扩展以适应(基于其他 css 属性)。
-
@freedomn-m 我添加了一个指向示例页面的链接,以便您查看。
-
a) 外部站点由于历史原因没有用 b) 我不知道导致问题的那个页面
-
我刚刚添加了两个屏幕截图,以便您查看
-
你的代码中没有 dropdown_anchor 类
标签: javascript jquery html css styles