Javascript 选择选项上的for循环不起作用
我试图在选择选项上做一个循环,但它不起作用。 代码仅处理第一个元素,而不处理其他元素。 在其他选项中,它们给出与第一个选项相同的结果。 如何使循环在选项上工作?我想编辑for循环,而不是整个代码 var billAmount=document.getElementById'bill-amount', serviceQuality=document.getElementById'quality', serviceQualityList=Array.fromdocument.QuerySelector所有“质量选项”, serviceQualityListLength=serviceQualityList.length, pepoleServing=document.getElementById'pepole', calculate=document.getElementById'calculate', tips=document.getElementById'tips'; calculate.onclick=函数{Javascript 选择选项上的for循环不起作用,javascript,Javascript,我试图在选择选项上做一个循环,但它不起作用。 代码仅处理第一个元素,而不处理其他元素。 在其他选项中,它们给出与第一个选项相同的结果。 如何使循环在选项上工作?我想编辑for循环,而不是整个代码 var billAmount=document.getElementById'bill-amount', serviceQuality=document.getElementById'quality', serviceQualityList=Array.fromdocument.QuerySelect
var serviceQualityListText=serviceQualityList.text, serviceQualityListLength=serviceQualityList.length, billAmountValue=billAmount.value, pepoleServingValue=pepoleServing.value; 对于变量i=0;i
不要使用onclick函数赋值。将更改事件侦听器添加到事件处理函数中,然后像读取任何其他表单元素一样,读取事件处理函数中的event.target.value。没有理由在此处查看元素。如果serviceQualityListText=Exellent-A single=指定值。要比较值,请使用==.mike pomax。。。你能给我更多的细节吗?请var serviceQualityListText=serviceQualityList.text,这个变量没有获得choosen选项的值,你需要在你的选择上处理更改事件,正如Mike所说,比较是使用==或==完成的。接下来,您将尝试读取数组的.text属性,这没有任何意义。另外,如果将值属性指定给s,则只需读取的值即可。
for (var i = 0; i < serviceQualityListLength; i++) {
if (serviceQualityListText == "Exellent") {
tips.textContent = (billAmountValue / 40) * pepoleServingValue;
} else if (serviceQualityListText == "Very Good") {
tips.textContent = (billAmountValue / 60) * pepoleServingValue;
} else if (serviceQualityListText == "Good") {
tips.textContent = (billAmountValue / 70) * pepoleServingValue;
} else if (serviceQualityListText == "Not Good") {
tips.textContent = (billAmountValue / 75) * pepoleServingValue;
} else {
tips.textContent = (billAmountValue * 0) * pepoleServingValue;
}
}