[英]How to customize an html dropdown menu using <div><span>
I'm trying to create a pricing table to showcase service pricing based on terms of purchase (Monthly, Annually, Trieannually).我正在尝试创建一个定价表来展示基于购买条款(每月、每年、三年一次)的服务定价。
Choosing an option from the dropdown changes the link attribute using javascript which is exactly what I want, however, the actual styling on the dropdown options seems to be rather difficult.从下拉列表中选择一个选项会使用 javascript 更改链接属性,这正是我想要的,但是,下拉选项的实际样式似乎相当困难。
Trying to achieve this for hours on end without any working solution.试图在没有任何可行解决方案的情况下连续数小时实现这一目标。
Attached is an image of what I am trying to achieve.附件是我想要实现的目标的图像。
Does anyone know what I am doing wrong?有谁知道我做错了什么?
<div class="ive-hpbox">
<h3>Simple Price Box</h3>
<div class="dropdown-plans">
<select id="dynamic_select">
<option value="cart.php?a=add&pid=1548&billingcycle=monthly">
<h3>Monthly</h3>
<span class="hp-price">$12.00/mo</span>
</option>
<option value="cart.php?a=add&pid=1548&billingcycle=annually" selected>
<h3>SAVE 50%</h3>
<span class="hp-disc-price">1 Year at <strike>$144.00/mo</strike></span>
<span class="hp-price">$72.00/mo</span>
</option>
<option value="cart.php?a=add&pid=1548&billingcycle=triennially">
<h3>SAVE 70%</h3>
<span class="hp-disc-price">3 Year at <strike>$432.00/mo</strike></span>
<span class="hp-price">$129.60/mo</span>
</option>
</select>
</div>
<p class="hecont act">Attractive selling introduction to the plan followed by an unordered list. <strong>Save huge</strong>
with a pro-plan!</p>
<ul>
<li><i class="fa fa-check"></i> Disk Storage Space</li>
<li><i class="fa fa-check"></i> Accounts</li>
<li><i class="fa fa-check"></i> Antivirus Filtering</li>
<li><i class="fa fa-check"></i> Anti-spam Filtering</li>
<li><i class="fa fa-check"></i> Auto Responders</li>
<li><i class="fa fa-check"></i> IMAP / POP3 Protocols</li>
<li><i class="fa fa-check"></i> Control Panel</li>
</ul>
<a class="but_small1" href="#features">View Features</a> <a id="order-btn"> Order now </a>
</div>
document.getElementById("dynamic_select").onclick = function() {
document.getElementById("order-btn").href = "https://example.com/"+this.value+"/";
}
.ive-hpbox{
width:350px;
border:1px solid #a1a1a1;
border-radius:.25em;
padding:10px;
text-align:center;
}
.ive-hpbox:hover{
box-shadow:0 0 10px rgba(0,0,0,.15);
}
#dynamic_select option .hp-saving {
font-size:26px;
}
#dynamic_select {
border: 1px solid #a1a1a1;
padding:10px;
text-align:center;
background:#fff;
width:90%;
}
.ive-hpbox ul{
display:block;
text-align:left;
}
https://jsfiddle.net/6rsgnmdy/52/ https://jsfiddle.net/6rsgnmdy/52/
This cannot be done using a select/option tag.这不能使用选择/选项标签来完成。
I have seen people doing this with a <input type=radio>
combined with a label
.我见过有人用
<input type=radio>
结合label
这一点。 Hide the radio button, and each option is being written out in the label.隐藏单选按钮,每个选项都写在 label 中。 Though then you still need to add JavaScript to show the selected value and the open/close to show all the options.
尽管如此,您仍然需要添加 JavaScript 以显示所选值和打开/关闭以显示所有选项。
Other people also might do this with div's, but I personally don't like it, as with the radio/label solution you are still controlling the form directly instead of using JavaScript and you only use JS for visibility.其他人也可能使用 div 执行此操作,但我个人不喜欢它,因为使用无线电/标签解决方案,您仍然直接控制表单而不是使用 JavaScript,并且您只使用 JS 来提高可见性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.