Html >

Html >,html,css,Html,Css,选择{ 高度:50px; 线高:50px; 字号:12号; } 这是使用ms下拉菜单: 数据资源是json。但是您不需要使用json。如果你愿意,你可以使用css Css示例: Json示例: HTML 剧本 <script> var jsonData = [ {description:'Choos your payment gateway', value:'', text:'Payment Gateway'},

选择{
高度:50px;
线高:50px;
字号:12号;
}


这是使用ms下拉菜单:

数据资源是json。但是您不需要使用json。如果你愿意,你可以使用css

Css示例:

Json示例:

HTML


剧本

<script>
        var jsonData = [
            {description:'Choos your payment gateway', value:'', text:'Payment Gateway'},
            {image:'https://via.placeholder.com/50', description:'My life. My card...', value:'amex', text:'Amex'},
            {image:'https://via.placeholder.com/50', description:'It pays to Discover...', value:'Discover', text:'Discover'},
            {image:'https://via.placeholder.com/50', title:'For everything else...', description:'For everything else...', value:'Mastercard', text:'Mastercard'},
            {image:'https://via.placeholder.com/50', description:'Sorry not available...', value:'cash', text:'Cash on devlivery', disabled:true},
            {image:'https://via.placeholder.com/50', description:'All you need...', value:'Visa', text:'Visa'},
            {image:'https://via.placeholder.com/50', description:'Pay and get paid...', value:'Paypal', text:'Paypal'}
        ];
        $("#byjson").msDropDown({byJson:{data:jsonData, name:'payments2'}}).data("dd");
    }
</script>

var jsonData=[
{说明:'Choos your payment gateway',值:'',文本:'payment gateway'},
{图像:'https://via.placeholder.com/50'说明:'我的生活.我的卡…',值:'美国运通',文本:'美国运通'},
{图像:'https://via.placeholder.com/50,描述:'It pays to Discover…',值:'Discover',文本:'Discover'},
{图像:'https://via.placeholder.com/50,标题:'For everything…',描述:'For everything…',值:'Mastercard',文本:'Mastercard'},
{图像:'https://via.placeholder.com/50,说明:'Sorry not available…',值:'cash',文本:'cash on devely',禁用:true},
{图像:'https://via.placeholder.com/50,描述:'All your need…',值:'Visa',文本:'Visa'},
{图像:'https://via.placeholder.com/50,说明:'Pay and get Pay…',值:'Paypal',文本:'Paypal'}
];
$(“#byjson”).msDropDown({byjson:{data:jsonData,name:'payments2'});
}
对我来说是一个很好的开始,我真的试图得到一个真正的JS免费答案,它仍然提供了Select with images所期望的所有功能,但遗憾的是嵌套表单失败了。我在这里发布了两个解决方案;我的主要解决方案使用了一行JavaScript,并且是一个完全不使用JavaScript的解决方案,在另一个表单中不起作用,但可能对nav菜单有用

不幸的是,代码中有一点重复,但是当您考虑Select是什么时,它是有意义的。当您单击某个选项时,它会将该文本复制到选定区域,即,单击4个选项中的1个不会更改4个选项,但顶部现在会重复您单击的选项。要对图像执行此操作,需要JavaScript、Orrr。。。您可以复制条目

在我的示例中,我们有一个游戏(产品)列表,其中有版本。每个产品还可以有扩展,扩展也可以有版本。对于每个产品,如果有多个版本,我们会为用户提供每个版本的列表,以及图像和特定版本的文本

<h4>@Model.Name</h4>
@if (Model.Versions.Count == 1)
{
    <div class="rich-select-option-body pl-2">
        <img src="@Model.Versions[0].ImageUrl" alt="">@Model.Versions[0].VersionName (@Model.Versions[0].Year)
    </div>
}
else
{
    <h5>Select the version</h5>
    <div class="rich-select custom-select">
        <div class="rich-select-dropdown">
            @foreach (var version in Model.Versions)
            {
                <div class="rich-select-option">
                    <input type="radio" name="game" id="game-@version.ProductId-@version.VersionId" @if (version == Model.Versions.First()) { @Html.Raw(" checked") ; } />
                    <div class="rich-select-option-body">
                        <label tabindex="-1">
                            <img src="@version.ImageUrl" alt="">@version.VersionName (@version.Year)
                        </label>
                    </div>
                </div>
            }
        </div>
        <input type="checkbox" id="rich-select-dropdown-button" class="rich-select-dropdown-button" />
        <label for="rich-select-dropdown-button"></label>
        <div class="rich-select-options">
            @foreach (var version in Model.Versions)
            {
                <div class="rich-select-option">
                    <div class="rich-select-option-body">
                        <label for="game-@version.ProductId-@version.VersionId" tabindex="-1" onclick="document.getElementById('rich-select-dropdown-button').click();">
                            <img src="@version.ImageUrl" alt=""> @version.VersionName (@version.Year)
                        </label>
                    </div>
                </div>
            }
        </div>
    </div>
}
@Model.Name
@如果(Model.Versions.Count==1)
{
@Model.Versions[0].VersionName(@Model.Versions[0].Year)
}
其他的
{
选择版本
@foreach(Model.Versions中的var版本)
{
@version.VersionName(@version.Year)
}
@foreach(Model.Versions中的var版本)
{
@version.VersionName(@version.Year)
}
}
使用JS取消选中复选框,我们可以在表单上有多个实例。在这里,我扩展显示了一个扩展列表,它在版本上也有相同的逻辑

<h5 class="mt-3">Include Expansions?</h5>
@foreach (var expansion in Model.Expansions)
{
    <div class="form-row">
        <div class="custom-control custom-checkbox w-100">
            <input type="checkbox" class="expansion-checkbox custom-control-input" id="exp-@expansion.ProductId">
            <label class="custom-control-label w-100" for="exp-@expansion.ProductId">

                @if (expansion.Versions.Count == 1)
                {
                    <div class="rich-select-option-body pl-2">
                        <img src="@expansion.ImageUrl" />@expansion.Name: @expansion.Versions[0].VersionName (@expansion.Versions[0].Year)
                    </div>
                }
                else
                {
                    <div class="rich-select custom-select">
                        <div class="rich-select-dropdown">
                            @foreach (var version in expansion.Versions)
                            {
                                <div class="rich-select-option">
                                    <input type="radio" name="exp-@version.ProductId" id="exp-@version.ProductId-@version.VersionId" @if (version == expansion.Versions.First()) { @Html.Raw(" checked") ; } />
                                    <div class="rich-select-option-body">
                                        <label tabindex="-1">
                                            <img src="@version.ImageUrl" alt="">@expansion.Name: @version.VersionName (@version.Year)
                                        </label>
                                    </div>
                                </div>
                            }
                        </div>

                        <input type="checkbox" id="rich-select-dropdown-button-@expansion.ProductId" class="rich-select-dropdown-button" />
                        <label for="rich-select-dropdown-button-@expansion.ProductId"></label>
                        <div class="rich-select-options">
                            @foreach (var version in expansion.Versions)
                            {
                                <div class="rich-select-option">
                                    <div class="rich-select-option-body">
                                        <label for="exp-@version.ProductId-@version.VersionId" tabindex="-1" onclick="document.getElementById('rich-select-dropdown-button-@expansion.ProductId').click();">
                                            <img src="@version.ImageUrl" alt="">@expansion.Name: @version.VersionName (@version.Year)
                                        </label>
                                    </div>
                                </div>
                            }
                        </div>
                    </div>
                }
            </label>
        </div>
    </div>
是否包含扩展?
@foreach(模型中的var扩展。扩展)
{
@if(expansion.Versions.Count==1)
{
@expansion.Name:@expansion.Versions[0]。VersionName(@expansion.Versions[0]。年份)
}
其他的
{
@foreach(expansion.Versions中的var版本)
{
@扩展名:@version.VersionName(@version.Year)
}
@foreach(expansion.Versions中的var版本)
{
@扩展名:@version.VersionName(@version.Year)
}
}
当然,这需要相当多的CSS,我只在其中加入了CSS,以减小这个已经庞大的答案的大小。我使用了Bootstrap 4来减少所需的数量,并允许它与其他Bootstrap控件和任何已创建的站点自定义相适应


图像设置为75px,但这可以在
中的5行中轻松更改。rich select
。rich select option body img

复制和。作为一般解决方案:如果可以,将图标作为SVG组合在一起,将它们导入到您选择的个人Unicode范围内的字体中,在
中使用该字体从IE 8.0开始,一切都支持,小巧而简单。
不一定用于选择单个值此插件有最奇怪的“要求”我曾经见过;如果定义了
,CSS和滚动功能就会中断。2015年,您是否有任何W3C有效的解决方案?没有重新实现选择框?@IvanKuckir-Pffff。W3C仍在“讨论”原因
<select name='state' style='height: 45px; font-family:Arial, FontAwesome;'>
<option value=''>&#xf039; &nbsp; All States</option>
<option value='enabled' style='color:green;'>&#xf00c; &nbsp; Enabled</option>
<option value='paused' style='color:orange;'>&#xf04c; &nbsp; Paused</option>
<option value='archived' style='color:red;'>&#xf023; &nbsp; Archived</option>
</select>
   <select>
      <option>100 &euro;</option>
      <option>89 &pound;</option>
    </select>
<select>
  <option style="background-image:url(euro.png);">100</option>
  <option style="background-image:url(pound.png);">89</option>
</select>
<!DOCTYPE html>
<html>
<body>

<style>
select#newlocale option[value="volvo"]   { background-color: powderblue;   }
select#newlocale option[value="opel"]   { background-color: red;   }
select#newlocale option[value="audi"]   { background-color: green;   }
</style> 

<select id="newlocale">
  <option value="volvo"><div >Volvo</div></option>
  <option value="saab">Saab</option>
  <option value="opel">Opel</option>
  <option value="audi">Audi</option>
</select>
  
</body>
</html>
<div id="byjson"></div>
<script>
        var jsonData = [
            {description:'Choos your payment gateway', value:'', text:'Payment Gateway'},
            {image:'https://via.placeholder.com/50', description:'My life. My card...', value:'amex', text:'Amex'},
            {image:'https://via.placeholder.com/50', description:'It pays to Discover...', value:'Discover', text:'Discover'},
            {image:'https://via.placeholder.com/50', title:'For everything else...', description:'For everything else...', value:'Mastercard', text:'Mastercard'},
            {image:'https://via.placeholder.com/50', description:'Sorry not available...', value:'cash', text:'Cash on devlivery', disabled:true},
            {image:'https://via.placeholder.com/50', description:'All you need...', value:'Visa', text:'Visa'},
            {image:'https://via.placeholder.com/50', description:'Pay and get paid...', value:'Paypal', text:'Paypal'}
        ];
        $("#byjson").msDropDown({byJson:{data:jsonData, name:'payments2'}}).data("dd");
    }
</script>
<h4>@Model.Name</h4>
@if (Model.Versions.Count == 1)
{
    <div class="rich-select-option-body pl-2">
        <img src="@Model.Versions[0].ImageUrl" alt="">@Model.Versions[0].VersionName (@Model.Versions[0].Year)
    </div>
}
else
{
    <h5>Select the version</h5>
    <div class="rich-select custom-select">
        <div class="rich-select-dropdown">
            @foreach (var version in Model.Versions)
            {
                <div class="rich-select-option">
                    <input type="radio" name="game" id="game-@version.ProductId-@version.VersionId" @if (version == Model.Versions.First()) { @Html.Raw(" checked") ; } />
                    <div class="rich-select-option-body">
                        <label tabindex="-1">
                            <img src="@version.ImageUrl" alt="">@version.VersionName (@version.Year)
                        </label>
                    </div>
                </div>
            }
        </div>
        <input type="checkbox" id="rich-select-dropdown-button" class="rich-select-dropdown-button" />
        <label for="rich-select-dropdown-button"></label>
        <div class="rich-select-options">
            @foreach (var version in Model.Versions)
            {
                <div class="rich-select-option">
                    <div class="rich-select-option-body">
                        <label for="game-@version.ProductId-@version.VersionId" tabindex="-1" onclick="document.getElementById('rich-select-dropdown-button').click();">
                            <img src="@version.ImageUrl" alt=""> @version.VersionName (@version.Year)
                        </label>
                    </div>
                </div>
            }
        </div>
    </div>
}
<h5 class="mt-3">Include Expansions?</h5>
@foreach (var expansion in Model.Expansions)
{
    <div class="form-row">
        <div class="custom-control custom-checkbox w-100">
            <input type="checkbox" class="expansion-checkbox custom-control-input" id="exp-@expansion.ProductId">
            <label class="custom-control-label w-100" for="exp-@expansion.ProductId">

                @if (expansion.Versions.Count == 1)
                {
                    <div class="rich-select-option-body pl-2">
                        <img src="@expansion.ImageUrl" />@expansion.Name: @expansion.Versions[0].VersionName (@expansion.Versions[0].Year)
                    </div>
                }
                else
                {
                    <div class="rich-select custom-select">
                        <div class="rich-select-dropdown">
                            @foreach (var version in expansion.Versions)
                            {
                                <div class="rich-select-option">
                                    <input type="radio" name="exp-@version.ProductId" id="exp-@version.ProductId-@version.VersionId" @if (version == expansion.Versions.First()) { @Html.Raw(" checked") ; } />
                                    <div class="rich-select-option-body">
                                        <label tabindex="-1">
                                            <img src="@version.ImageUrl" alt="">@expansion.Name: @version.VersionName (@version.Year)
                                        </label>
                                    </div>
                                </div>
                            }
                        </div>

                        <input type="checkbox" id="rich-select-dropdown-button-@expansion.ProductId" class="rich-select-dropdown-button" />
                        <label for="rich-select-dropdown-button-@expansion.ProductId"></label>
                        <div class="rich-select-options">
                            @foreach (var version in expansion.Versions)
                            {
                                <div class="rich-select-option">
                                    <div class="rich-select-option-body">
                                        <label for="exp-@version.ProductId-@version.VersionId" tabindex="-1" onclick="document.getElementById('rich-select-dropdown-button-@expansion.ProductId').click();">
                                            <img src="@version.ImageUrl" alt="">@expansion.Name: @version.VersionName (@version.Year)
                                        </label>
                                    </div>
                                </div>
                            }
                        </div>
                    </div>
                }
            </label>
        </div>
    </div>