简体   繁体   English

如何<span>在javascript中</span>自定义<span>?</span>

[英]How to customize <span> in javascript?

I found this code on the internet and made some modifications for my need. 我在互联网上找到了此代码,并根据需要进行了一些修改。 I style first select list with css but i can't do the same for the second select list. 我用CSS为第一个选择列表设置样式,但是第二个选择列表我不能做同样的事情。 I think it needs some js modifications but my js knowledge is not that good. 我认为它需要对js进行一些修改,但是我的js知识不是那么好。 How do i customize "slist2" like i did to "slist1" with css? 如何像使用CSS对“ slist1”所做的那样自定义“ slist2”?

 <!-- The first select list --> <style> #slist1 { height: 35px; border: 3px solid #0c3f6b; border-radius: 25px; } #scontent { color: #0c3f6b; font-size: 25px } #content { width: 290px; float: left; padding: 5px 15px; } #middle { width: 294px; /* Account for margins + border values */ float: left; padding: 5px 15px; margin: 0px 5px 5px 5px; } #sidebar { width: 270px; padding: 5px 15px; float: left; } </style> <section id="content"> PICK UP LOCATION <select name="slist1" div id=slist1 onchange="SList.getSelect('slist2', this.value);"> <option>- - -</option> <option value="newyork">New York</option> <option value="miami">Miami</option> </select> </section> <!-- Tags for the seccond dropdown list, and for text-content --> <section id="middle"> <span id="slist2"></span> </section> <section id="sidebar"> <div id="scontent"></div> </section> <script> <!-- /* Script Double Select Dropdown List, from: coursesweb.net/javascript/ */ var SList = new Object(); // JS object that stores data for options // HERE replace the value with the text you want to be displayed near Select var txtsl2 = 'DROP OFF LOCATION'; /* Property with options for the Seccond select list The key in this object must be the same with the values of the options added in the first select The values in the array associated to each key represent options of the seccond select */ SList.slist2 = { "newyork": ['San Diego', 'Portland','Ohio', 'San Francisco'], "miami": ['San Diego', 'Portland','Ohio', 'San Francisco'], }; /* Property with text-content associated with the options of the 2nd select list The key in this object must be the same with the values (options) added in each Array in "slist2" above The values of each key represent the content displayed after the user selects an option in 2nd dropdown list */ SList.scontent = { "San Diego": '45€', "Portland": '60€', "Ohio": '35€', "San Francisco": '25€', }; /* From here no need to modify */ // function to get the dropdown list, or content SList.getSelect = function(slist, option) { document.getElementById('scontent').innerHTML = ''; // empty option-content if (SList[slist][option]) { // if option from the last Select, add text-content, else, set dropdown list if (slist == 'scontent') document.getElementById('scontent').innerHTML = SList[slist][option]; else if (slist == 'slist2') { var addata = '<option>- - -</option>'; for (var i = 0; i < SList[slist][option].length; i++) { addata += '<option value="' + SList[slist][option][i] + '">' + SList[slist][option][i] + '</option>'; } document.getElementById('slist2').innerHTML = txtsl2 + ' <select name="slist2" onchange="SList.getSelect(\\'scontent\\', this.value);">' + addata + '</select>'; } } else if (slist == 'slist2') { // empty the tag for 2nd select list document.getElementById('slist2').innerHTML = ''; } } --> </script> 

You would do it like this: 您可以这样做:

#slist1,
#slist2 {
    height: 35px;
    border: 3px solid #0c3f6b;
    border-radius: 25px;
}

or even better, like this: 甚至更好,像这样:

.slist {
    height: 35px;
    border: 3px solid #0c3f6b;
    border-radius: 25px;
}

Then change your html to use a class (class="slist") instead of an ID. 然后将您的html更改为使用类(class =“ slist”)代替ID。

It's also worth noting that they may not look EXACTLY alike since the span and select elements have very different default styles, AND style elements are a pain to style (in a cross-browser way, that is) 还值得注意的是,它们可能看起来不完全相同,因为span和select元素具有非常不同的默认样式,而AND样式元素给样式带来痛苦(即跨浏览器方式)

<style>
[id^="slist"] {
    height: 35px;
    border: 3px solid #0c3f6b;
    border-radius: 25px;
}
</style>

 <select id="slist1"></select>
 <select id="slist2"></select>
 <select id="slist3"></select>

It makes your all elements with ID of value begins with "slist" styled the same. 它使您所有ID为value的元素都以样式相同的“ slist”开头。

如何使用自定义 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>

暂无
暂无

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

相关问题 如何自定义一个javascript文件 - How to customize a javascript file 如何自定义 JavaScript 提示? - How to customize the JavaScript prompt? 如何使用自定义 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> 如何在Javascript中为跨度分配一个类? - how to assign a class to a span in Javascript? 如何使用 Javascript 更改跨度文本? - How to change Span text with Javascript? 如何序列化 OpenTelemetry Javascript Span - How to Serialize an OpenTelemetry Javascript Span 如何自定义Javascript Dialogue选项? - How to customize the Javascript Dialogue options? 如何在Javascript中通过变量自定义字符串? - How to customize a string by variable in Javascript? 怎么分裂 <p> <span>你好</span> </p> 使用javascript <span>你好</span> - how to split <p><span>Hello</span></p> to <span>Hello</span> using javascript 如何使用JavaScript从跨度获取数据并将其传输到其他跨度 - how to get a data from a span and transfer it to an other span using javaScript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM