gpt4 book ai didi

javascript - 将值设置为其他输入字段

转载 作者:行者123 更新时间:2023-12-03 09:05:03 24 4
gpt4 key购买 nike

这是一个 html 代码

<select id="product">
<option value="laptop">Laptop</option>
<option value="candy">Candy</option>
<option value="ebook" selected="selected">Ebook</option>
</select>
<input type="text" id="priceProduct">

这是一段 JavaScript 代码

var e = document.getElementById("product");
var strUser = console.log(e.options[e.selectedIndex].value);
if(strUser == "ebook"){
console.log('This is ebook');
}

所以,我只想从 select 元素中输入一些值,例如 $ 5.00 来输入 id PriceProduct (我什至无法将输出提供给控制台)。我完全迷路了。我很欣赏你的回答。

jsfiddle link

最佳答案

将代码更改为:

var e = document.getElementById("product");
var strUser = e.options[e.selectedIndex].value;
console.log(strUser);
if(strUser == "ebook"){
console.log('This is ebook');
document.getElementById("priceProduct").value = "$5.00";
}
// -- prints:
// ebook
// This is ebook

console.log 没有返回值。

关于javascript - 将值设置为其他输入字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32208564/

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