javascript - 如何通过弹出菜单中的选定选项更改进行设置?

标签 javascript jquery html css

我有这些选择:

<form>
<select id="poSelect" >
<option selected disabled>Choose here</option>
<option id="buyeroption" value="100101">I am a Buyer</option>                                                                           
<option id="garageoption" value="100102">I am a Garage</option>                                                                           
</select>

<label>Full Name</label>
<input type="text" />

<label>Email Address</label>
<input type="email" />

<label>Password</label>
<input type="password" />

<label id="industrylabel" >Select Your Brand</label>
<select id="industryoption">
<option selected disabled>Select</option>   
<option value="Renault">Renault</option>
<option value="Pegaut">Pegaut</option>
<option value="Citroen">Citroen</option>
</select>

<div class="form-check-label">
<input id="send_updates" type="checkbox" />
<label for="send_updates">Send me occasional email updates</label>
 </div> 

所以我需要的是当用户选择我是买家标签“选择您的品牌”并且行业选项选择隐藏但当我点击我是车库时出现。

最佳答案

<form>
<select id="mySelect">
<option id="apple">Apple</option>
<option id="orange">Orange</option>
<option id="pineapple">Pineapple</option>
<option id="banana">Banana</option>
</select>
</form>
<p></p>

<button onclick="myFunction()">textbox1</button>
<p id="demo"></p> 
<script>
function myFunction() {
var x = document.getElementById("mySelect").options.namedItem("banana").text;
document.getElementById("demo").innerHTML = x;
 }
 </script>

如果您想更改任何内容,也许您想要类似的东西,请检查此链接:- http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_select_options6

关于javascript - 如何通过弹出菜单中的选定选项更改进行设置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39332153/

相关文章:

javascript - 迭代并从 JSON 获取某些索引的唯一值

javascript - 如何在 TypeScript 声明源文件中声明嵌套函数?

javascript - 拖放时清除 jQuery data()

css - HTML 颜色选择器输入

javascript - 在 MongoDB 中更新具有不同 ID 的多个文档

javascript - 使用 jQuery Wan Spinner 插件的多个字段

javascript - 单击链接时在跨度上切换类

javascript - 如何使用外部 javascript 验证输入?

html - 如何使我创建的这些菜单项在 IE7 中看起来正确?

html - 将两个词彼此相邻放置 css