簡體   English   中英

將值設置為其他輸入字段

[英]Set value to other input field

這是一個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鏈接

將您的代碼更改為:

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沒有返回值。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM