簡體   English   中英

單擊顯示按鈕后如何獲取結果文本作為結果按鈕的結果?

[英]How to get value text as result for result button after clicking Show button?

我在這里問有關JavaScript的問題。 我是JavaScript的新手,所以如果我做錯了,請原諒。 有人可以幫助我獲得結果。 從下拉列表中選擇任何狀態后,“顯示”按鈕應為我提供狀態值。 可能嗎?

  <h1>Please select a State</h1> <select id = "district"> <option value = "Tiruvanandapuram">Kerala</option> <option value = "Chennai">Tamil Nadu</option> <option value = "New Delhi">Delhi</option> </select> <input type = "button" value = "Show" onclick = "" /> <INPUT type="text" ID="add" id="txtresult" NAME="result" VALUE=""> 

`

這樣做:

 var sel = document.getElementById("district"); function show(){ var txt = document.getElementById("add"); txt.value = sel.options[sel.selectedIndex].value; } 
 <h1>Please select a State</h1> <select id = "district"> <option value = "Kerala">Kerala</option> <option value = "Chennai">Tamil Nadu</option> <option value = "New Delhi">Delhi</option> </select> <input type = "button" value = "Show" onclick = "show()" /> <INPUT type="text" id="add" id="txtresult" NAME="result" VALUE=""> 

試試一個簡單的代碼,希望對大家有所幫助

    <script type="text/javascript">
function run() {
    document.getElementById("srt").value = document.getElementById("district").value;
}
</script>

<h1>Please select a State</h1>

<select id = "district">
   <option value="Tiruvanandapuram">Kerala</option>
   <option value="Chennai">Tamil Nadu</option>
   <option value="Delhi">Delhi</option>
</select>

<input type = "button" value = "Show" onclick="run()"/>
<INPUT type="text" ID="srt"  id="txtresult" NAME="result" VALUE="">

在click =“”內部添加以下代碼

var e = document.getElementById('district'); document.getElementById('txtresult')。value = e.options [e.selectedIndex] .value;

底部的文本框中有兩個Id屬性,請刪除id =“ Add”。

希望這可以幫助。

試試這個:HTML-

<h1>Please select a State</h1>

<select id="district">
<option value="Tiruvanandapuram">Kerala</option>
<option value="Chennai">Tamil Nadu</option>
<option value="New Delhi">Delhi</option>
</select>

<input type= "button" value= "show" id="btn" onclick= show_district() />
<input type="text" id = sss value = "" />

JavaScript:

function show_district() {
  var selector = document.getElementById('district');
  var value = selector[selector.selectedIndex].value;
  document.getElementById('sss').value = value;
}

暫無
暫無

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

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