简体   繁体   English

如何制作将文本​​放置在文本字段中的下拉菜单

[英]How Do I Make a Dropdown Menu That Places A Text In a text Field

How do i make a drop down menu that when an option is chosen it creates a text that is placed in a text box. 我如何制作一个下拉菜单,当选择一个选项时,它将创建一个放置在文本框中的文本。 For Example, Dropdown menu option1 = "are good" 例如,下拉菜单option1 =“好”

i want the output to be, "Waffles Are Good". 我希望输出为“华夫饼很好”。 Waffles Will Automatically be there and they select an option from the drop down menu and it places the text "Are Good" Onto A Text Field 华夫饼将自动存在,并且它们从下拉菜单中选择一个选项,并将文本“ Are Good”放置到文本字段中

<p>Waffles <span id="whatarewaffles"></span></p>
<p>
    <label>What's with the waffles? 
        <select id="wafflemachine">
            <option value="are good">they are good</option>
            <option value="are delicious">they are delicious</option>
        </select>
    </label>
</p>

<script>
document.getElementById("wafflemachine").onchange = function() {
    document.getElementById("whatarewaffles").innerHTML = this.options[this.selectedIndex].value;
};
</script>

You mean something like this? 你的意思是这样的吗?

As per my understanding I made this fiddle . 根据我的理解,我做了这个小提琴 Let me know is it helpful for you. 让我知道这对您有帮助。

HTML HTML

<select id="data1">
  <option value="good">good</option>
  <option value="too good">too good</option>
  </select>
<input type="text" id="data2" value="Waffles good"/>

Jquery jQuery的

$("#data1").val("good").change(function(){
var k=($("#data1").find(":selected").text());
    $("#data2").val('Waffles'+k);

});

In javascript you can use jquery to do this. 在javascript中,您可以使用jquery来做到这一点。

You can check my full code here https://jsfiddle.net/tmhnfL9d/ 您可以在这里查看我的完整代码https://jsfiddle.net/tmhnfL9d/

 $('#selectme').change(function(){ $("#sentence").html('Waffles'); answer = $(this).val(); $("#sentence").append(answer); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <select id="selectme"> <option value= "">Please Select</option> <option value= " are Good">are Good</option> <option value= " are Bad">are Bad</option> </select> <p id="sentence">Waffles</p> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM