Javascript html新增我想显示在<;中选择的内容;选择>;
我想展示甘草的味道、巧克力的颜色和所选的配料。例如“青苹果,白苹果,圣诞花洒” 请帮助我确定我是否应该给每个选项一个数值。我这么做只是因为。请随意将其更改为文本或任何您认为有效的内容。如果你看到什么的话,我希望你能给我一些关于结构的建议。先谢谢你Javascript html新增我想显示在<;中选择的内容;选择>;,javascript,html,select,Javascript,Html,Select,我想展示甘草的味道、巧克力的颜色和所选的配料。例如“青苹果,白苹果,圣诞花洒” 请帮助我确定我是否应该给每个选项一个数值。我这么做只是因为。请随意将其更改为文本或任何您认为有效的内容。如果你看到什么的话,我希望你能给我一些关于结构的建议。先谢谢你 <div class="Licorice Flavors"> <select id="Licorice"> <option selected disabled>Licorice Flavor</option&g
<div class="Licorice Flavors">
<select id="Licorice">
<option selected disabled>Licorice Flavor</option>
<option value="1">Green Apple</option>
<option value="2">Blue Raspberry</option>
<option value="3">Red Raspberry</option>
<option value="4">Watermelon</option>
<option value="5">Chocolate</option>
<option value="6">Orange</option>
<option value="7">Piña Colada</option>
</select>
</div>
<div class="Chocolate Color">
<select id="Chocolate">
<option selected disabled>Chocolate Color</option>
<option value="8">White Chocolate</option>
<option value="9">Dark Chocolate</option>
</select>
</div>
<div class="Toppings">
<select id="Toppings">
<option selected disabled>Toppings</option>
<option value="10">Christmas Sprinkles</option>
<option value="11">Rainbow Sprinkles</option>
<option value="12">Valentine's Day</option>
</select>
</div>
<a href="#" id="link">Add to Cart</a>
<div id="result"></div>
<script type="text/javascript">
document.getElementById('link').onclick = function() {
var a = parseInt(document.getElementById('Licorice').value);
var b = parseInt(document.getElementById('Chocolate').value);
var c = parseInt(document.getElementById('Toppings').value);
var answer = (a,b,c);
document.getElementById('result').innerText = answer;
};
</script>
甘草香精
青苹果
蓝树莓
红莓
西瓜
巧克力
橙色
皮尼亚·科拉达
巧克力色
白巧克力
黑巧克力
浇头
圣诞小雨
彩虹洒
情人节
document.getElementById('link')。onclick=function(){
var a=parseInt(document.getElementById('Licorice').value);
var b=parseInt(document.getElementById('Chocolate').value);
var c=parseInt(document.getElementById('Toppings').value);
var答案=(a、b、c);
document.getElementById('result').innerText=answer;
};
关闭。试试这个:
var answer = [a,b,c].join(" ");
document.getElementById('result').innerText = answer;
检查是否可以使用jquery,或者是否只使用javascript
使用链接中的代码
<script>
function myNewFunction(sel)
{
alert(sel.options[sel.selectedIndex].text);
}
</script>
<select id="box1" onChange="myNewFunction(this);" >
<option value="98">dog</option>
<option value="7122">cat</option>
<option value="142">bird</option>
</select>
函数myNewFunction(sel)
{
警报(sel.options[sel.selectedIndex].text);
}
狗
猫
鸟
我想知道您是否想这样做。
document.getElementById('link')。onclick=function(){
var a=parseInt(document.getElementById('Licorice').value);
var b=parseInt(document.getElementById('Chocolate').value);
var c=parseInt(document.getElementById('Toppings').value);
var answer=“(“+a+”、“+b+”、“+c+””);
document.getElementById('result').innerText=answer;
};代码>
甘草香精
青苹果
蓝树莓
红莓
西瓜
巧克力
橙色
皮尼亚·科拉达
巧克力色
白巧克力
黑巧克力
浇头
圣诞小雨
彩虹洒
情人节
试试这个:
var answer = [a,b,c].join(" ");
document.getElementById('result').innerText = answer;
document.getElementById('link').onclick = function() {
var a = document.getElementById('Licorice').value;
var b = document.getElementById('Chocolate').value;
var c = document.getElementById('Toppings').value;
var answer = [a,b,c].join(", ");
document.getElementById('result').innerText = answer;
};
你想做什么?你能详细说明一下吗?有3个这样的菜单,我只想结果显示我选择的文本形式。然后最终想要给这个组合一个值,就像一个项目编号一样。太好了!请考虑投票,并将其标记为正确答案。很抱歉,我不能投票,我没有足够的声誉,但是gladsocc也给出了一个非常类似的回答。但是我非常感谢你的帮助。非常感谢。