[英]Set value to other input field
Here an html code 这是一个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">
and this is a javascript code 这是一个javascript代码
var e = document.getElementById("product");
var strUser = console.log(e.options[e.selectedIndex].value);
if(strUser == "ebook"){
console.log('This is ebook');
}
So, i just want to give some value like $ 5.00 to input id priceProduct (I cant even give output to console) from select element. 因此,我只想给select元素输入$ 5.00这样的值来输入id priceProduct(我什至不能将输出提供给控制台)。 I'm totally lost. 我完全迷路了。 I appreciate your answer. 感谢您的回答。
Change your code to: 将您的代码更改为:
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
doesn't have a return value. console.log
没有返回值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.