简体   繁体   English

如何将两个字段组合成第三个标签?

[英]How to Combine Two Fields into a Third One For Tags?

So I have two fields, a regular input and a dropdown.所以我有两个字段,一个常规输入和一个下拉菜单。 I want these two fields to be combined into a third field (which is to create tags).我希望将这两个字段组合成第三个字段(即创建标签)。 In the third field, the tags can be removed by pressing an X, but nothing can be entered in there otherwise.在第三个字段中,可以通过按 X 来删除标签,否则无法在其中输入任何内容。

I've seen this done somewhere, but for the life of me, I can't remember where or what this process is called so I can't find the plugin.我在某处看到过这样做,但是对于我的生活,我不记得这个过程在哪里或叫什么,所以我找不到插件。

This is the furthest I can get.这是我能得到的最远距离。 I feel like it is a jQuery plugin which can do it, but, I'm not sure.我觉得它是一个可以做到的 jQuery 插件,但是,我不确定。

<form>
  <label for="fname">First name:</label>
  <input type="text" id="fname" name="fname"><br><br>
  <label for="lname">Last name:</label>
 <select id="lname">
  <option value="Bryant">Bryant</option>
  <option value="oneal">O'Neal</option>
  <option value="Jordan">Jordan</option>
  <option value="Pippen">Pippen</option>
</select><br><br>

<input type="submit" value="Combine">
<br><br>
   <label for="fullname">Full name tags:</label>
  <input type="text" id="fullname" name="fullname" disabled><br><br>

</form>

Try this尝试这个

 function myFunction(){ var fname = $('#fname').val(); var lname = $('#lname').val(); $('#fullname').val(fname + " " + lname); }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script> <form> <label for="fname">First name:</label> <input type="text" id="fname" name="fname"><br><br> <label for="lname">Last name:</label> <select id="lname" > <option value="Bryant">Bryant</option> <option value="oneal">O'Neal</option> <option value="Jordan">Jordan</option> <option value="Pippen">Pippen</option> </select><br><br> <input type="button" value="Combine" onclick="myFunction()"> <br><br> <label for="fullname">Full name tags:</label> <input type="text" id="fullname" name="fullname" disabled><br><br> </form>

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

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