gpt4 book ai didi

javascript - 如何在单击按钮时在 javascript 中隐藏/显示下拉菜单

转载 作者:行者123 更新时间:2023-11-28 16:28:23 25 4
gpt4 key购买 nike

我试图向用户显示一个下拉列表,但只有当用户单击一个按钮时,我尝试了几种方法但没有成功,我现在将两个按钮和选择框放在同一个 div 中,但它仍然没有在职的。当用户点击“添加股票”按钮时,它应该打开下拉菜单。

<head><h1>CRS</h1></head>
<button id = 'newEntry' onclick="newBill()">Create New Bill</button>
<button id= 'clearEntry'> Reset </button>
<button id= 'dailyReport' > Report </button>
<div>
<button id= 'AdditemToStock' onclick="askCategory()">Add Stock</button>
<select style="visibility:hidden;" id="showInDropDown">
<option disabled="disabled" selected="selected">Choose Category</option>
</select>
</div>
<div id="NewBillMsg"> </div>
<div id="addToCartMsg"> </div>

<div id="itemList" style="display:none">

<h3>Select items</h3>
<select name="items" id="itemIndex" onclick="selectedItem()">
<option selected="selected">Select Items</option>
<option value="chocolate">chocolate</option>
<option value="Eggs">Eggs</option>
<option value="Bread">Bread</option>
<option value="Milk">Milk</option>
</select>
</div>

<script>
function cashRegister() {
total= 0;
addBill:function () {
this.total+=itemCost;
document.getElementById('NewBillMsg').innerHTML = "New";
document.getElementById('itemList').style.display="block";
},

scan: function(item,quantity) {
switch (item) {
case "Eggs": this.add(0.98 * quantity); break;
case "Milk": this.add(1.23 * quantity); break;
case "Bread": this.add(4.99 * quantity); break;
case "chocolate": this.add(0.45 * quantity); break;
}
return true;
//addToCart: function () {
//document.getElementById('addToCartMsg').innerHTML = "Enter Quantity ";
//},
askCategory: function () {
button.onclick = function() {
document.getElementById('showInDropDown').style.display="block";
},
};
</script>

最佳答案

这里有很多语法错误。修复了其中的大部分。以下代码应该可以工作:

<button id='newEntry' onclick="newBill()">
Create New Bill</button>
<button id='clearEntry'> Reset </button>
<button id='dailyReport'> Report </button>
<div>
<button id='AdditemToStock' onclick="askCategory()">Add Stock</button>
<select style='display:none;' id="showInDropDown">
<option disabled="disabled" selected="selected">Choose Category</option>
</select>
</div>
<div id="NewBillMsg"> </div>
<div id="addToCartMsg"> </div>
<div id="itemList" style="display:none">
<h3>Select items</h3>
<select name="items" id="itemIndex" onclick="selectedItem()">
<option selected="selected">Select Items</option>
<option value="chocolate">chocolate</option>
<option value="Eggs">Eggs</option>
<option value="Bread">Bread</option>
<option value="Milk">Milk</option>
</select>
</div>
<script>
function cashRegister() {
var total = 0,
addBill = function() {
this.total += itemCost;
document.getElementById('NewBillMsg').innerHTML = "New";
document.getElementById('itemList').style.display = "block";
},

scan = function(item, quantity) {
switch (item) {
case "Eggs":
this.add(0.98 * quantity);
break;
case "Milk":
this.add(1.23 * quantity);
break;
case "Bread":
this.add(4.99 * quantity);
break;
case "chocolate":
this.add(0.45 * quantity);
break;
}
};
}

var askCategory = function() {
document.getElementById('showInDropDown').style.display = "block";
};
</script>

关于javascript - 如何在单击按钮时在 javascript 中隐藏/显示下拉菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40671381/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com