简体   繁体   English

如何使用自定义 html 下拉菜单<div><span></span></div><div id="text_translate"><p>我正在尝试创建一个定价表来展示基于购买条款(每月、每年、三年一次)的服务定价。</p><p> 从下拉列表中选择一个选项会使用 javascript 更改链接属性,这正是我想要的,但是,下拉选项的实际样式似乎相当困难。</p><p> 试图在没有任何可行解决方案的情况下连续数小时实现这一目标。</p><p> 附件是我想要实现的目标的图像。</p><p> <a href="https://i.stack.imgur.com/afsZC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/afsZC.png" alt="在此处输入图像描述"></a></p><p> 有谁知道我做错了什么?</p><pre> &lt;div class="ive-hpbox"&gt; &lt;h3&gt;Simple Price Box&lt;/h3&gt; &lt;div class="dropdown-plans"&gt; &lt;select id="dynamic_select"&gt; &lt;option value="cart.php?a=add&amp;pid=1548&amp;billingcycle=monthly"&gt; &lt;h3&gt;Monthly&lt;/h3&gt; &lt;span class="hp-price"&gt;$12.00/mo&lt;/span&gt; &lt;/option&gt; &lt;option value="cart.php?a=add&amp;pid=1548&amp;billingcycle=annually" selected&gt; &lt;h3&gt;SAVE 50%&lt;/h3&gt; &lt;span class="hp-disc-price"&gt;1 Year at &lt;strike&gt;$144.00/mo&lt;/strike&gt;&lt;/span&gt; &lt;span class="hp-price"&gt;$72.00/mo&lt;/span&gt; &lt;/option&gt; &lt;option value="cart.php?a=add&amp;pid=1548&amp;billingcycle=triennially"&gt; &lt;h3&gt;SAVE 70%&lt;/h3&gt; &lt;span class="hp-disc-price"&gt;3 Year at &lt;strike&gt;$432.00/mo&lt;/strike&gt;&lt;/span&gt; &lt;span class="hp-price"&gt;$129.60/mo&lt;/span&gt; &lt;/option&gt; &lt;/select&gt; &lt;/div&gt; &lt;p class="hecont act"&gt;Attractive selling introduction to the plan followed by an unordered list. &lt;strong&gt;Save huge&lt;/strong&gt; with a pro-plan.&lt;/p&gt; &lt;ul&gt; &lt;li&gt;&lt;i class="fa fa-check"&gt;&lt;/i&gt; Disk Storage Space&lt;/li&gt; &lt;li&gt;&lt;i class="fa fa-check"&gt;&lt;/i&gt; Accounts&lt;/li&gt; &lt;li&gt;&lt;i class="fa fa-check"&gt;&lt;/i&gt; Antivirus Filtering&lt;/li&gt; &lt;li&gt;&lt;i class="fa fa-check"&gt;&lt;/i&gt; Anti-spam Filtering&lt;/li&gt; &lt;li&gt;&lt;i class="fa fa-check"&gt;&lt;/i&gt; Auto Responders&lt;/li&gt; &lt;li&gt;&lt;i class="fa fa-check"&gt;&lt;/i&gt; IMAP / POP3 Protocols&lt;/li&gt; &lt;li&gt;&lt;i class="fa fa-check"&gt;&lt;/i&gt; Control Panel&lt;/li&gt; &lt;/ul&gt; &lt;a class="but_small1" href="#features"&gt;View Features&lt;/a&gt; &lt;a id="order-btn"&gt; Order now &lt;/a&gt; &lt;/div&gt; 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; }</pre><p> <a href="https://jsfiddle.net/6rsgnmdy/52/" rel="nofollow noreferrer">https://jsfiddle.net/6rsgnmdy/52/</a></p></div>

[英]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 来提高可见性。

如何到达<span>内部的 html 标签</span><div>使用 Java 脚本?</div><div id="text_translate"><p> 我有一个放置在div内的span标签,如下所示:</p><pre> &lt;div onclick="doActiveCheckBox('color1')" id="sss" class="test form-check form-option form-check-inline mb-2"&gt; &lt;input class="test form-check-input" type="radio" name="color" id="color1" data-bs-label="colorOption" value="/تاریک" checked=""&gt; &lt;label class="form-option-label rounded-circle" for="color1"&gt;&lt;span style="border:inherit; border-block-color:purple;" class="form-option-color rounded-circle" style="background-image: url(/img/ProductColors/green1.jpg)"&gt;&lt;/span&gt;&lt;/label&gt; &lt;/div&gt;</pre><p> 我想在单击input标签时为span标签设置border ,并且也不想在span中使用任何id 。 我尝试了以下方法:</p><p> 1:</p><pre> var d=document.getElementById("sss").getElementsByTagName("span"); d.style.border = "thick solid #0000FF";</pre><p> 2:</p><pre> var d=document.getElementById("sss").getElementsByClassName(); for (var i = 1; i &lt;= d.length; i++) { d[1].style.border = "thick solid #0000FF"; }</pre><p> 但他们都没有正常工作? 那么有人会帮忙吗?</p></div> - How to reach a html <span> tag inside a <div> using Java Script?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用HTML和CSS创建下拉菜单 - how to make dropdown menu using html & css 自定义下拉菜单 - Customize Dropdown Menu 如何使用javascript添加,删除html中的div或span? - How to add,remove div or span in html using javascript? 如何到达<span>内部的 html 标签</span><div>使用 Java 脚本?</div><div id="text_translate"><p> 我有一个放置在div内的span标签,如下所示:</p><pre> &lt;div onclick="doActiveCheckBox('color1')" id="sss" class="test form-check form-option form-check-inline mb-2"&gt; &lt;input class="test form-check-input" type="radio" name="color" id="color1" data-bs-label="colorOption" value="/تاریک" checked=""&gt; &lt;label class="form-option-label rounded-circle" for="color1"&gt;&lt;span style="border:inherit; border-block-color:purple;" class="form-option-color rounded-circle" style="background-image: url(/img/ProductColors/green1.jpg)"&gt;&lt;/span&gt;&lt;/label&gt; &lt;/div&gt;</pre><p> 我想在单击input标签时为span标签设置border ,并且也不想在span中使用任何id 。 我尝试了以下方法:</p><p> 1:</p><pre> var d=document.getElementById("sss").getElementsByTagName("span"); d.style.border = "thick solid #0000FF";</pre><p> 2:</p><pre> var d=document.getElementById("sss").getElementsByClassName(); for (var i = 1; i &lt;= d.length; i++) { d[1].style.border = "thick solid #0000FF"; }</pre><p> 但他们都没有正常工作? 那么有人会帮忙吗?</p></div> - How to reach a html <span> tag inside a <div> using Java Script? 带有href和div的html / jquery下拉菜单 - html/jquery dropdown menu with a href and div 如何在同一行中对齐span和html下拉列表? - How to align the span and html dropdown in same line? 使用HTML和CSS创建下拉菜单,但如果使用div分区页面则无法导航到所有子菜单 - Using Html and Css to create DropDown Menu but not able to navigate to all the submenu if using div to partition page 如何<span>在javascript中</span>自定义<span>?</span> - How to customize <span> in javascript? 自定义html数据列表下拉列表 - Customize html datalist dropdown 使用AJAX在div中加载下拉菜单内容 - Load dropdown menu content in div using AJAX
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM