gpt4 book ai didi

javascript - 取值,用输出更新字段

转载 作者:太空宇宙 更新时间:2023-11-04 10:30:45 28 4
gpt4 key购买 nike

我的目标:是通过我的函数更新字段获取选定值并使用函数输出值运行它。

问题:当我从列表中选择值时,它不会触发函数,也不会更新字段。

感谢您的帮助。

HTML

<form id="someform">
<select id="sample" onChange="dIIN()">
<option>12</option>
<option>14</option>
<option>16</option>
<option>18</option>
<option>20</option>
<option>22</option>
<option>24</option>
<option>27</option>
<option>30</option>
<option>32</option>
</select>
</form>

<tr>
<td>Quantity to be dredged</td>
<td><input type="number" value="450000" class="" id="quantity-dredged" ></input></td>
</tr>

JavaScript

var dIIN = function() {
var dredgeSize = document.getElementById('sample');
var foo = 0;
if (dredgeSize <= 12) {
foo = 36;
} else if (dredgeSize <= 14) {
foo = 42;
} else if (dredgeSize <= 16) {
foo = 44;
} else if (dredgeSize <= 18) {
foo = 48;
} else if (dredgeSize <= 20) {
foo = 60;
} else if (dredgeSize <= 22) {
foo = 62;
} else if (dredgeSize <= 24) {
foo = 62;
} else if (dredgeSize <= 26) {
foo = 68;
} else if (dredgeSize <= 28) {
foo = 68;
} else if (dredgeSize <= 30) {
foo = 74;
}
document.getElementById('quantity-dredged').value = foo;
};

这是一个 codePen example

最佳答案

改变行:

var dredgeSize = document.getElementById('sample');

到:

var dredgeSize = document.getElementById('sample').value;

Demo

关于javascript - 取值,用输出更新字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36505520/

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