簡體   English   中英

如何在 p-tag 中獲取純文本和選定的選項?

[英]how to get the pure text and selected option in a p-tag?

選擇 5 和 2 后,是否有任何解決方案可以得到字符串 output,如:5 大於 2?

 <p class="showTxt" id="showTxt"> <select size="2"> <option>1</option> <option>2</option> <option>3</option> <option>4</option> <option>5</option> </select> <p> greater than</p> <select size="1"> <option>1</option> <option>2</option> <option>3</option> <option>4</option> <option>5</option> </select> </p>

這是你想要的嗎?

 function showText(ele) { document.getElementById("2").innerHTML = document.getElementById("1").options[document.getElementById("1").selectedIndex].text+" is greater than "+ele.options[ele.selectedIndex].text; }
 <p class="showTxt" id="showTxt"> <select size="2" id="1"> <option>1</option> <option>2</option> <option>3</option> <option>4</option> <option>5</option> </select> <p> greater than</p> <select size="1" onchange="showText(this)"> <option>1</option> <option>2</option> <option>3</option> <option>4</option> <option>5</option> </select> </p> <p id="2"></p>

暫無
暫無

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

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