[英]View option as a box and not dropdown(only one option)
I have a select tag to display a set of connections with size set to 3 : 我有一个选择标签来显示一组大小为3的连接:
<select float="left" id="selectedConnection" name="selectedConnection" size="3" style="overflow:auto;">
The connections get added and deleted dynamically, and when they get deleted, if number of connections become less than 3, I decrement the size attribute. 连接会动态添加和删除,当连接被删除时,如果连接数少于3,则我会减小size属性。 But when only one connection remains, the size becomes 1, it is showing it in a dropdown shape. 但是,当仅保留一个连接时,大小变为1,它以下拉形状显示。 Like this : 像这样 :
I don't want the dropdown. 我不要下拉列表。 Any way to resolve this ? 有什么办法解决这个问题?
Try this: 尝试这个:
HTML: HTML:
<select float="left" id="selectedConnection" name="selectedConnection" size="3" style="overflow:auto;">
<input type="text" id="selectedConnectionText" name="selectedConnection" style="display:none">
JQUERY: JQUERY:
$( document ).ready(function() {
if($('select#selectedConnection option').length == 1)
{
$("#selectedConnection").hide();
$('#selectedConnectionText').val($("#selectedConnection option:first").val());
$('#selectedConnectionText').show();
}
});
Okay so basically what I have done is , I have a textbox next to select box in hidden state. 好的,基本上我已经完成了,在隐藏状态的选择框旁边有一个文本框。 Now i don't know how you are populating the select box, so on load jquery will check for number of options your select has. 现在,我不知道您如何填充选择框,因此在加载时,jQuery将检查您选择的选项数量。 If it has 1 it will give the option value to the text box, hide your select box and show the text box. 如果值为1,它将为文本框提供选项值,隐藏选择框并显示文本框。
JSFiddle : https://jsfiddle.net/oepbdtw2/ JSFiddle: https ://jsfiddle.net/oepbdtw2/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.